Skip to content

React Native managing multiple screens with same store #3054

Answered by murat-mehmet
murat-mehmet asked this question in Q&A
Discussion options

You must be logged in to vote

Ok thanks for the response. This is the decorator I prepared for such screens.

const overrideStore = (...storeKeys) => (WrappedComponent) => {
  return function (props) {
    let overrides = {};
    const stores = React.useContext(MobXProviderContext)
    storeKeys.forEach(storeKey => {
      if (!stores[storeKey])
        throw new Error(`'${storeKey}' store does not exist`)
      const StoreType = stores[storeKey].constructor;
      overrides[storeKey] = new StoreType(stores);
    })
    return (
        <Provider {...overrides}>
          <WrappedComponent {...props} />
        </Provider>
    )
  };
}

usage:

@overrideStore('product')
@inject('product')
@observer
class ProductDetail e…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by murat-mehmet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants