Christian Lessard
Christian Lessard

Reputation: 425

Can't Access Redux State in App.js

I need access to redux state in App.js.

I am currently using a Navigation Component "Switch" to handle my Application routing, and I am using connect and mapStateToProps, which allows me to see my application state in the mapStateToProps function. This issue is this.props in App.js does not return any state whatsoever.

I am trying to pass in isAuthenticated to Switch via my redux state.

App.js:

function mapStateToProps(state) {
  console.log(state.token)
  return{
    token: state.token
  }

}

let Container = connect(mapStateToProps, null)(Switch(this.props.token.isAuthenticated))


export default class App extends React.Component {

  constructor(props) {
    super(props);

    this.state = {
      signedIn: false,
      checkedSignIn: false,
    };
  }

    render () {
      console.log('props')
      console.log(this.props)

      const { checkedSignIn, signedIn } = this.state;


    return (
      <Provider store={store}>
        <PersistGate loading={null} persistor={persistor}>
          <Container />
        </PersistGate>
      </Provider>
    )

  }
    }

Upvotes: 1

Views: 1394

Answers (1)

Christian Lessard
Christian Lessard

Reputation: 425

I got it to work by creating another component called "Root" and having my connect function there.

Upvotes: 2

Related Questions