Skip to content

Instantly share code, notes, and snippets.

@StevenJL
Created September 1, 2018 06:17
Show Gist options
  • Save StevenJL/53187fcc9fa6c0e056c71574bccb01c3 to your computer and use it in GitHub Desktop.
Save StevenJL/53187fcc9fa6c0e056c71574bccb01c3 to your computer and use it in GitHub Desktop.
class App extends React.Component {
render() {
return (
<div>
<button onClick={this.props.async_update}>Click To Update State After Five Seconds</button>
</div>
);
}
}
const ConnectedApp = connect(
(state) => {
return { ...state };
},
(dispatch) => {
return {
async_update: () => {
setTimeout(() => {
dispatch({type: UPDATE}, payload: "new_value" ), 5000
};
}
})(App);
const reducer = (state = { current_state: "Old State"}, action) => {
switch (action.type) {
case UPDATE:
return { ...state, current_state: action.payload };
default:
return state;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment