I have a prop called friends which is being listed as a checkboxes (default: unselected).
Example output:
o Bob Smith
o Tom Brown
How can I save the id's of all the names that are selected?
E.g. both are ticked/selected -> ids 1 and 2 is stored.
This is what I have so far:
class SelectFriends extends Component {
constructor(props) {
super(props)
this.state = {
SelectedFriendsIds: [],
}
}
render() {
const { SelectedFriendsIds } = this.state
const { userId, friends, addFriendsTo } = this.props
return (
<div>
<SubHeader title="Add Friends..." />
<div>
{friends
.mapEntries(([friendId, frn]) => [
friendId,
<div key={friendId}>
<input
value={friendId}
type='checkbox'
// onChange={ () => console.log("do something")
defaultChecked={false} />
{frn.firstName} {frn.lastName}
</div>,
])
.toList()}
</div>
<div>
<Button style="blue" name="Done" onClick={() => addFriendsTo(SelectedFriendIds, userId)} />
</div>
</div>
)
}
}
export default SelectFriends