我想知道人们在 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)
这用作稍后在组件中的合成事件的回调 …
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) 根据工作中的领导,两者之间的区别
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 语句的“名义”情况。请忽略这一点,因为我试图完全复制引发讨论的相关代码。
caching ×1
gitlab-ci ×1
if-statement ×1
javascript ×1
lodash ×1
no-op ×1
reactjs ×1
standards ×1