小编El *_*imo的帖子

call()在其自身上下文中的函数

var f = function() {
  this.x = 5;
  (function() {
    this.x = 3;
  })();
  console.log(this.x);
};

f.call(f);

f();

f.call();
Run Code Online (Sandbox Code Playgroud)

var f作为f.call(f)输出运行5。当作为f()f.call()输出运行时3

在每种情况下会发生什么?内部功能this指的是什么?

javascript this

22
推荐指数
2
解决办法
1117
查看次数

如何使用 Create React App 运行特定测试

在使用 CRA v.1 创建的应用程序中,我需要运行特定的测试文件。我该怎么做?有一个--testPathIgnorePatterns标志可以添加到npm test脚本中以忽略文件或路径,但是如何从命令行使用 CRA 运行特定的测试文件?

unit-testing create-react-app

16
推荐指数
2
解决办法
1万
查看次数

GraphQL Codegen 使用 typescript-urql 复制 RegisterDocument

下面的 codegen.ts 配置会导致RegisterDocument条目重复。

代码生成器.ts:

const config: CodegenConfig = {
  overwrite: true,
  schema: "http://localhost:4000/graphql",
  documents: "src/graphql/**/*.graphql",
  generates: {
    "src/generated/graphql": {
      preset: "client",
      plugins: [
        "typescript-urql"
      ],
      config: {
        documentVariableSuffix: 'test2'
      }
    }
  }
};
Run Code Online (Sandbox Code Playgroud)

输出:

export const RegisterDocument = {"kind":"Document", ...}

export const RegisterDocument = gql`
    mutation Register($username: String!, $password: String!) {
  register(options: {username: $username, password: $password}) {
    errors {
      field
      message
    }
    user {
      id
      username
      createdAt
    }
  }
}
    `;

export function useRegisterMutation() {
  return Urql.useMutation<RegisterMutation, RegisterMutationVariables>(RegisterDocument); …
Run Code Online (Sandbox Code Playgroud)

graphql-codegen

7
推荐指数
2
解决办法
2900
查看次数

Flatpickr 在没有选择时选择今天的关闭日期

当我打开然后关闭 Flatpickr 实例而不选择日期时,它会将其设置为今天的日期。如何防止这种行为?当用户未设置时,我需要日期输入保持为空。

Flatpickr 实例用 React-Flatpickr 包装。

<Flatpickr
    ref={fpStartDate}
    className='th-input-container__input'
    value={startDate}
    onClose={(selectedDates, dateStr, instance) => { 
        if (selectedDates.length > 0) {
            setInputValue(1);
            setCurrentPage(1);
            setStartDate(selectedDates[0]);
        }
    }}
    options={{
        enableTime: true,
        enableSeconds: true,
        dateFormat: 'd.m.Y, H:i:S',
        locale: Russian,
        mode: 'single',
        time_24hr: true,
        minuteIncrement: 1,
        allowInput: true,
        disableMobile: true,
        monthSelectorType: 'dropdown',
        onOpen: function(selectedDates, dateStr, instance) {
            setTimeout(function() {
                instance.open();
            }, 200);
        }
    }}
    placeholder='from'
/>
Run Code Online (Sandbox Code Playgroud)

reactjs flatpickr

6
推荐指数
1
解决办法
347
查看次数

WebStorm 2018.1.4 + ESLint:TypeError:this.CliEngine不是构造函数

我的配置是这样。

WebStorm 2018.1.4; ESLint 6.4; 节点12.8; npm 6.10.2;Windows 8.1。

如何消除线程标题中的错误?

这是一个代码示例。

import {
  GET_DAILY_SUCCESS,
  GET_HOURLY_SUCCESS,
  GET_MINUTE_SUCCESS
} from './types';
import {
  getDailyToUsd,
  getHourlyToUsd,
  getMinuteToUsd
} from '../api/cryptocompare';
import { setError } from './error';

export const getDaily = (fsym = 'BTC') => async dispatch => {
  try {
    const list = await getDailyToUsd(fsym);

    dispatch({
      type: GET_DAILY_SUCCESS,
      currency: fsym,
      list
    });
  } catch(err) {
    dispatch(setError(err.Message));
  }
};
Run Code Online (Sandbox Code Playgroud)

webstorm eslint

4
推荐指数
5
解决办法
1529
查看次数

使用去抖 onChange 处理程序设置输入值

在我的 React Hooks 应用程序中,我需要让用户在输入字段中键入 1000 毫秒。当 1000 毫秒到期时,将发送带有输入值的 API 请求。

<input type='text' name='name' className='th-input-container__input' onChange={evt => testFunc2(evt.target.value)} />
Run Code Online (Sandbox Code Playgroud)

该值设置为testFunc2(evt.target.value)

const testFunc2 = useCallback(debounce((text) => setNameFilter(text), 1000), []);
Run Code Online (Sandbox Code Playgroud)

一旦nameFilter设置为新值,useEffect就会发出 API 请求,因为nameFilter它是依赖项。这样,仅使用最终的用户输入而不是每个击键值来查询 API,但输入仍不受控制。当我将当前nameFilter值添加到输入时,value={nameFilter}用户无法在输入中键入,并且输入仅接收最后键入的字符。

如何让用户输入的字符显示在输入中?

debouncing react-hooks

3
推荐指数
1
解决办法
3063
查看次数

WebStorm块注释中的前导空格

WebStorm以我喜欢的方式产生单行样式注释,并在//:后面留空格// comment here。在注释掉代码块时,如何在前导注释文字之后和结尾处添加空格?这是我所拥有的:

/*<line of code>
<line of code>
<line of code>*/
Run Code Online (Sandbox Code Playgroud)

这就是我想要的:

/* <line of code>
<line of code>
<line of code> */
Run Code Online (Sandbox Code Playgroud)

Add a space at comment start 不会的

webstorm

2
推荐指数
1
解决办法
275
查看次数