Skip to content Skip to sidebar Skip to footer

Switch Store Using Condition In Render Using Redux

My application has 2 side, first side is the client app, second side is admin dashboard app. To make it DRY I decided to pass the store in the provider base on user role, so that I

Solution 1:

The problem is probably from getUserRole() this is a blocking task and this returns a null and role should not be null.

My suggestion here would be to have an APP component which resolves the value from getUserRole() and returns an Admin or User component based on the result from getUserRole()

Remove redux store implementation from App component and place implementation in individual Admin or User components.


Solution 2:

As you said, there are two sides client and admin.

So,you can assume default value for you store implementation.

Assume, you always want to load client store by default.

then render should be,

render() {

    if (this.role === 'admin') {
      return this.renderSwitchProvider(adminStore)
    }else if(this.role === 'member'){

        return this.renderSwitchProvider(store)
    }



}

Post a Comment for "Switch Store Using Condition In Render Using Redux"