rmo
v1.0.0
Published
Encapsulating model with react hooks.
Downloads
1
Readme
Rmo
Rmo helps you encapsulate models with react hooks.
Install
yarn add rmo
# or use npm
npm i rmo
Create a model
import rmo from 'rmo'
// create a view model by react hooks
const useModel = rmo(() => {
const [a, setA] = useState('a')
const [b, setB] = useState('b')
return { a, b, setA, setB }
})
// use model in Parent
function Parent() {
const model = useModel()
return (
<>
<div>{ model.a }</div>
<button onClick={setB}>setB</button>
</>
)
}
// use model anywhere...
function Child() {
const model = useModel()
return (
<>
<div>{ model.b }</div>
<button onClick={setA}>setA</button>
</>
)
}