React
Install
npm install overmind overmind-reactHook
// overmind/index.js
import {
createStateHook,
createActionsHook,
createEffectsHook,
createReactionHook
} from 'overmind-react'
import { state } from './state'
import * as actions from './actions'
export const config = {
state,
actions
}
export const useState = createStateHook()
export const useActions = createActionsHook()
export const useEffects = createEffectsHook()
export const useReaction = createReactionHook()
// index.js
import * as React from 'react'
import { render } from 'react-dom'
import { createOvermind } from 'overmind'
import { Provider } from 'overmind-react'
import { config } from './overmind'
import App from './components/App'
const overmind = createOvermind(config)
render((
<Provider value={overmind}>
<App />
</Provider>
), document.querySelector('#app'))
// components/App.jsx
import * as React from 'react'
import { useState, useActions, useEffects, useReaction } from '../overmind'
const App = () => {
// General
const state = useState()
const actions = useActions()
const effects = useEffects()
const reaction = useReaction()
// Or be specific
const { isLoggedIn } = useState().auth
const { login, logout } = useActions().auth
return <div />
}
export default AppRendering
Passing state as props
Reactions
Higher Order Component
Rendering
Passing state as props
Reactions
React Native
Last updated