Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import store from '../../store'
- import {connect} from "react-redux";
- import {bindActionCreators} from "redux";
- /* Your store has lots of different properties, but this particular component only needs to use `loggedin`.
- What we will do is copy the value from store's props to a local-only state value. */
- constructor() {
- super();
- this.state = {
- // Use store version of property if available, otherwise set to a default (false here)
- loggedin: (typeof store.getState().authentication.loggedin !== 'boolean') ? false : store.getState().authentication.loggedin
- }
- store.subscribe(() => {
- // This is a listener for changes in any and all store properties.
- this.setState({
- loggedin: store.getState().authentication.loggedin,
- })
- })
- }
- // your render here....
- // After component definition:
- const mapStateToProps = state => ({})
- const mapDispatchToProps = dispatch => bindActionCreators({}, dispatch)
- export default connect(
- mapStateToProps,
- mapDispatchToProps
- )(App)
Add Comment
Please, Sign In to add comment