In JSX, we can indicate attribute value dynamically like:
<div className={this.state.className}>This is a div.</div>
Is it possible to indicate attribute (including attribute name and attribute value) dynamically? Like:
const value = emptyValue ? "" : "value='test'";
<input {value} />
That means, once emptyValue is true, "input" tag should not include "value" attribute (value="" is different from no value attribute, as one is show empty in input field, another is show existing text in input field).
<input value={emptyValue ? "" : "test"}>?emptyValueis true, "value" attribute should not exist in the "input".const props = { value: "test", otherProp: "blah" }and then<input {...props}>value={emptyValue ? null : "test"}