Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hotsen/7fa11bf3b1c7d059436057c8200925d4 to your computer and use it in GitHub Desktop.
Save hotsen/7fa11bf3b1c7d059436057c8200925d4 to your computer and use it in GitHub Desktop.
React Native Navigation Mobx Boilerplate + Apollo2
// Thanks to github/@megahertz - https://gist.github.com/megahertz/3aad3adafa0f7d212b81f5e371863637
import { Children } from "react"
import { Provider } from 'mobx-react/native';
import { ApolloProvider } from 'react-apollo';
const SPECIAL_REACT_KEYS = { children: true, key: true, ref: true };
export default class MobxRnnProvider extends Provider {
props: {
store: Object
};
context: {
mobxStores: Object
};
getChildContext() {
const stores = {};
// inherit stores
const baseStores = this.context.mobxStores;
if (baseStores) {
for (let key in baseStores) {
stores[key] = baseStores[key];
}
}
// add own stores
for (let key in this.props.store) {
if (!SPECIAL_REACT_KEYS[key]) {
stores[key] = this.props.store[key];
}
}
return {
mobxStores: stores
};
}
render() {
return(
<ApolloProvider client={this.props.store['ApolloClient'].client}>
{ Children.only(this.props.children) }
</ApolloProvider>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment