Created
September 1, 2018 06:17
-
-
Save StevenJL/53187fcc9fa6c0e056c71574bccb01c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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