小编Par*_*gun的帖子

函数道具是否需要“noop”[lodash] 默认参数?

我想知道人们在 React 中使用可选的默认函数时有什么建议。

我已经看到我们的代码库混合使用 () => {} 和 lodash noop。

哪个更可取?

这是关于正确编码技术的一般问题。

export default ({
  name = '',
  value = '',
  label = name,
  type = 'text',
  noLabel = false,
  placeholder = '',
  required = false,
  isInvalid = false,
  showBar = true,
  inputRef,
  onChange = () => {},
  onBlurCb, // <-- THE BIT IN QUESTION
  ...props
}) => (
  <Component initialState={{ isFocused: false, hasValue: false }}>
    {({ state, setState }) => (
      <InputContainer
        isFocused={state.isFocused}
        isInvalid={isInvalid}
        noLabel={noLabel}
        {...props}
      >
...
Run Code Online (Sandbox Code Playgroud)

这用作稍后在组件中的合成事件的回调 …

javascript no-op lodash reactjs

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

由于政策原因,Gitlab 缓存未上传

Not uploading cache {name of branch} due to policy我的 gitlab 运行程序出现错误。我的.yaml文件如下所示:

stages:
  - test
  - staging
  - publish
  - deploy

# cache using branch name
# https://gitlab.com/help/ci/caching/index.md
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .yarn
    - node_modules/
  policy: pull

before_script:
  - yarn install --cache-folder .yarn

test:
  stage: test
  image: node:14
  script:
    - yarn install
    - yarn test

pages:
  stage: staging
  image: alekzonder/puppeteer
  except:
    - master
  script:
    - yarn install
    - yarn compile
    - yarn build

publish:
  stage: publish
  image: …
Run Code Online (Sandbox Code Playgroud)

caching gitlab-ci gitlab-ci-runner

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

If-else vs if not-if

根据工作中的领导,两者之间的区别

if (invalid) {
   ...some code
}

if (!invalid) {
  ...some code
}
Run Code Online (Sandbox Code Playgroud)

if (invalid) {
  ...some code
} else {
  ...some code
}
Run Code Online (Sandbox Code Playgroud)

可以理解为一种风格选择。我想知道人们在哪里划线以及您会如何考虑这一点。

PS:是的,我知道否定不应该是 if 语句的“名义”情况。请忽略这一点,因为我试图完全复制引发讨论的相关代码。

standards if-statement

0
推荐指数
1
解决办法
1312
查看次数