英文:
React-Select with Formik - S6544 promises should not be misused
问题
我有以下代码:
<Select
options={publisherOptions}
onChange={selectedOption => formik.setFieldValue("publisherId", selectedOption?.value)} />
它可以工作!但是我收到了 TypeScript 警告 S6544:
Promises should not be misused.
Promise-returning function provided to attribute where a void return was expected.
有没有更好的方法来编写代码以避免这个警告?
英文:
I have following code
<Select
options={publisherOptions}
onChange={selectedOption => formik.setFieldValue("publisherId", selectedOption?.value)} />
and it works! However I am getting typescript warning S6544
> Promises should not be misused.
Promise-returning function provided to attribute where a void return was expected.
Is there some better way how to code this to avoid the warning?
答案1
得分: 1
不要从函数中返回 Promise。
selectedOption => {
formik.setFieldValue...;
}
在函数体周围添加大括号意味着它返回 return
语句所指定的内容,而不是单个表达式的结果。(由于没有 return
语句,它返回 undefined
(上下文所期望的 void 值)。
英文:
Don't return the promise from the function.
selectedOption => {
formik.setFieldValue...;
}
Adding braces around the function body means it returns whatever the return
statement says instead of the result of the single expression. (Since there is no return
statement, it returns undefined
(a void value as is expected by the context).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论