We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
< Component if={...}>
ref: facebook/jsx#65 (comment)
在 jsx 里直接 { conditional && <Component /> }
{ conditional && <Component /> }
The text was updated successfully, but these errors were encountered:
在 jsx 里直接 { conditional && }
如果conditional是true的话, 没有什么问题, 如果为非true的话, 则返回的是conditional的值, 这很危险, 比如可能的值为'', 0, false, 这3个值并不是严格意义上的undefined.
conditional
true
'', 0, false
undefined
在React Native上, 如果Component是Text, 程序可能会crash.
Component
Text
Sorry, something went wrong.
有点多虑了,这个是react推荐的做法: https://facebook.github.io/react/docs/conditional-rendering.html#inline-if-with-logical-ampamp-operator
Therefore, if the condition is true, the element right after && will appear in the output. If it is false, React will ignore and skip it.
如果实在怕conditional是非boolean的话可以 !!
!!
我个人习惯inline的conditional, 为了最快的移植Vue的代码, 封装了一层<View if>, 可以考虑将if都改为inline.
<View if>
fixed: #68
No branches or pull requests
ref: facebook/jsx#65 (comment)
在 jsx 里直接
{ conditional && <Component /> }
The text was updated successfully, but these errors were encountered: