Last active
July 16, 2019 09:24
-
-
Save radzserg/4797e10423978c707cc16b648075cfed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // DIContext.ts | |
| import React from "react"; | |
| import DIContainer, { IDIContainer } from "rsdi"; | |
| const DIContext = React.createContext<IDIContainer>(new DIContainer()); | |
| export default DIContext; | |
| // App.ts | |
| // build container only once | |
| const diContainer: IDIContainer = configureDIContainer(); | |
| class App extends PureComponent { | |
| render() { | |
| // now we can get values from container | |
| const apolloClient = diContainer.get<ApolloClient<any>>(APP_DEP.APOLLO_CLIENT); | |
| const reduxStore = diContainer.get<Store>(APP_DEP.REDUX_STORE); | |
| const browserHistory = diContainer.get<History>(APP_DEP.BROWSER_HISTORY); | |
| return ( | |
| <ErrorBoundary> | |
| <ApolloProvider client={apolloClient}> {/* we still need these contexts, but that's fine */} | |
| <Provider store={reduxStore}> | |
| <DIContext.Provider value={diContainer}> {/* we will need our own context */} | |
| <Router history={browserHistory}> | |
| <Layout> | |
| <Switch> | |
| <Route path="/" component={HomePage} exact={true} /> | |
| </Switch> | |
| </Layout> | |
| </Router> | |
| </DIContext.Provider> | |
| </Provider> | |
| </<ApolloProvider> | |
| </ErrorBoundary> | |
| ); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment