-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from cerebral/hooksprovider
feat(overmind-react): add provider
- Loading branch information
Showing
4 changed files
with
114 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
88 changes: 88 additions & 0 deletions
88
packages/overmind-website/examples/guide/usingovermindwithreact/hook_provider.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
export default (ts) => | ||
ts | ||
? [ | ||
{ | ||
fileName: 'overmind/index.ts', | ||
code: ` | ||
import { Overmind, IConfig } from 'overmind' | ||
import { createHook } from 'overmind-react' | ||
import { state } from './state' | ||
import * as actions from './actions' | ||
const config = { | ||
state, | ||
actions | ||
} | ||
declare module 'overmind' { | ||
interface Config extends IConfig<typeof config> {} | ||
} | ||
export const overmind = new Overmind(config) | ||
export const useOvermind = createHook<typeof config>() | ||
`, | ||
}, | ||
{ | ||
fileName: 'components/index.tsx', | ||
code: ` | ||
import * as React from 'react' | ||
import { render } from 'react-dom' | ||
import { Provider } from 'overmind-react' | ||
import { overmind } from './overmind' | ||
import App from './components/App' | ||
render(( | ||
<Provider value={overmind}> | ||
<App /> | ||
</Provider> | ||
), document.querySelector('#app')) | ||
`, | ||
}, | ||
{ | ||
fileName: 'components/App.tsx', | ||
code: ` | ||
import * as React from 'react' | ||
import { useOvermind } from '../overmind' | ||
const App: React.FunctionComponent = () => { | ||
const { state } = useOvermind() | ||
return <div>{state.title}</div> | ||
} | ||
export default App | ||
`, | ||
}, | ||
] | ||
: [ | ||
{ | ||
fileName: 'overmind/index.js', | ||
code: ` | ||
import { Overmind } from 'overmind' | ||
import { createHook } from 'overmind-react' | ||
const overmind = new Overmind({ | ||
state: {}, | ||
actions: {} | ||
}) | ||
export const useOvermind = createHook(overmind) | ||
`, | ||
}, | ||
{ | ||
fileName: 'components/App.jsx', | ||
code: ` | ||
import React from 'react' | ||
import { useOvermind } from '../overmind' | ||
const App = () => { | ||
const { state, actions, effects, addMutationListener } = useOvermind() | ||
return <div /> | ||
} | ||
export default App | ||
`, | ||
}, | ||
] |
This file contains 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