Want to conditionally add attributes to React components? Apparently, for certain attributes, React is intelligent enough to omit the attribute if the value you pass to it is not truthy.
For example:
1 2 3 4 5 6 7 8 9 10 | var InputComponent = React.createClass({ render: function() { var required = true; var disabled = false; return ( <input type="text" disabled={disabled} required={required} /> ); } }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.