I\'ve read in the React docs that \"if\" type statements can\'t be used in JSX code, because of the way JSX renders into javascript, it doesn\'t work out as one would expect
render-if is a light weight function that will render an element if a condition is satisfied
class MyComponent extends Component {
render() {
return (
{renderIf(1 + 2 === 3)(
The universe is working
)}
);
}
}
class MyComponent extends Component {
render() {
const ifTheUniverseIsWorking = renderIf(1 + 2 === 3);
return (
{ifTheUniverseIsWorking(
The universe is still wroking
)}
)
}
}
const ifEven = number => renderIf(number % 2 === 0);
const ifOdd = number => renderIf(number % 2 !== 0);
class MyComponent extends Component {
render() {
return (
{ifEven(this.props.count)(
{this.props.count} is even
)}
{ifOdd(this.props.count)(
{this.props.count} is odd
)}
);
}
}