Instantly share code, notes, and snippets.

Embed
What would you like to do?
solid-user-list-enhanced
export class UserList extends Component {
static propTypes = {
fetchUsers: PropTypes.func.isRequired,
saveUsers: PropTypes.func.isRequired
};
state = {
users: [{id: 1, name: 'Jim', surname: 'Smith', age: 33}]
};
componentDidMount() {
const users = this.props.fetchUsers();
this.setState({users});
}
render() {
return (
<div>
{this.props.children({
users: this.state.users,
saveUsers: this.saveUsers,
onUserChange: this.onUserChange
})}
</div>
);
}
saveUsers = () => {
this.props.saveUsers(this.state.users);
};
onUserChange = (user) => {
// change user in the state
};
}
@kwelch-eb

This comment has been minimized.

Copy link

kwelch-eb commented Oct 24, 2018

Just a not the saveUsers and onUserChange you are passing to children is referencing state. Looks to be a simple copy/paste slip.

Loved the post!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment