Skip to content
New issue

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

Do not need < Component if={...}> #65

Closed
rlog opened this issue Oct 31, 2016 · 4 comments
Closed

Do not need < Component if={...}> #65

rlog opened this issue Oct 31, 2016 · 4 comments

Comments

@rlog
Copy link
Contributor

rlog commented Oct 31, 2016

ref: facebook/jsx#65 (comment)

在 jsx 里直接 { conditional && <Component /> }

@e1emeb0t
Copy link
Contributor

e1emeb0t commented Oct 31, 2016

在 jsx 里直接 { conditional && }

如果conditionaltrue的话, 没有什么问题, 如果为非true的话, 则返回的是conditional的值, 这很危险, 比如可能的值为'', 0, false, 这3个值并不是严格意义上的undefined.

在React Native上, 如果ComponentText, 程序可能会crash.

@rlog
Copy link
Contributor Author

rlog commented Oct 31, 2016

有点多虑了,这个是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的话可以 !!

@e1emeb0t
Copy link
Contributor

我个人习惯inline的conditional, 为了最快的移植Vue的代码, 封装了一层<View if>, 可以考虑将if都改为inline.

@e1emeb0t
Copy link
Contributor

fixed: #68

@e1emeb0t e1emeb0t closed this as completed Nov 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants