Browse Source

Use null instead of '' in ternary expression

A blank string ('') resolves to <span></span> which produces a warning when place inside a <tr>
main
Kale 9 years ago
parent
commit
cf5236600c
  1. 2
      tips/03-if-else-in-JSX.md

2
tips/03-if-else-in-JSX.md

@ -30,7 +30,7 @@ React.createElement("div", {id: if (condition) { 'msg' }}, "Hello World!");
That's not valid JS. You probably want to make use of a ternary expression:
```js
ReactDOM.render(<div id={condition ? 'msg' : ''}>Hello World!</div>, mountNode);
ReactDOM.render(<div id={condition ? 'msg' : null}>Hello World!</div>, mountNode);
```
If a ternary expression isn't robust enough, you can use `if` statements outside of your JSX to determine which components should be used:

Loading…
Cancel
Save