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 | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
kwelch-eb commentedOct 24, 2018
Just a not the
saveUsers
andonUserChange
you are passing to children is referencingstate
. Looks to be a simple copy/paste slip.Loved the post!