1.0.0 • Published 3 years ago

rmo v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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>
    </>
  )
}