Consider this
componentDidMount() {
const { currentUserId, userList } = this.props;
//I get these from redux' mapStateToProps function;
//these are not passed down as regular props.
Mousetrap.bind(['shift+right'], () =>
nextUser(currentUserId, userList)
);
}
Say I have 10 users in my list, and we start with user 1. When I start the app, it will go from user 1 to user 2; However, it won't go any further since the value of currentUserId will eternally be user 1.
How can I circumvent this and have the arguments be dynamic, so that the arguments will be updated?
Edit: currentUserId & userList are passed on to the Component via Redux
If you want things to be dynamic, consider copying the currentUserId to the state in the constructor and adjusting the state as needed with this.setState({currentUserId: }) Example:
}
I don't know how your nextUser function works but it if it returns the next userId, you could do:
in the componentDidMount().