I'm quite new to React and was working through the "Thinking in React" example, I noticed they used refs for updating state, but I also read on SO that using refs isn't that good in the long run, so I tried to redo this without using refs:
var SearchBar = React.createClass({
handleChange: function(event) {
if (event.target.type ==='text') {
this.props.onUserInput(
event.target.value,
this.props.inStockOnly
);
} else {
this.props.onUserInput(
this.props.filterText,
event.target.checked
);
}
},
render: function() {
return (
<form>
<input
type="text"
placeholder="Search..."
value={this.props.filterText}
onChange={this.handleChange}
/>
<p>
<input
type="checkbox"
checked={this.props.inStockOnly}
onChange={this.handleChange}
/>
{' '}
Only show products in stock
</p>
</form>
);
}
});
It works but it seems repetitive, how would someone comfortable with React do this without refs?