I'm busy working through this tutorial on React + Redux and I was wondering what the !! was for when setting the checked property of the checkbox.
render() {
const onClick = () => store.dispatch({type: 'TOGGLE'});
return (
<div>
<h1>To dos</h1>
<div>
Learn Redux
<input
type="checkbox"
checked={!!this.state.checked}
onClick={onClick}
/>
</div>
{
this.state.checked ? (<h2>Done!</h2>) : null
}
</div>
);
If you remove the !! the component still works as expected.
If I leave the !! but remove the onClick property then nothing happens because the state isn't changed so the control never re-renders. The checkbox remains unchecked and the Done! message never displays
If I remove the onClick and the !!, the checkbox changes from unchecked to checked (despite it being bound to state.checked which is false by default) but the state obviously never changes because the Done! message won't display.
What is the !! doing?