Created
October 2, 2019 12:32
-
-
Save alonbardavid/92fa7ee2a65d6d9000935e1cc251c788 to your computer and use it in GitHub Desktop.
Patterns for deriving state gist12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ToppingSelection(props){ | |
const {options,selected,onChange} = props; | |
function handleInputChange(event){ | |
const value = event.target.name; | |
if ( selected.includes(value)){ | |
onChange(selected.filter(option=>option !== value)); | |
} else { | |
onChange(selected.concat(value)); | |
} | |
} | |
return <div> | |
{options.map(option=> | |
<label key={option.value}> | |
{option.text} | |
<input type={checkbox} checked={selected.includes(option.value)} | |
onChange=(this.handleInputChange} name={option} /> | |
</label> | |
)} | |
</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment