1.0.7 • Published 1 year ago

lzy-ruzy v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

一个为Lzy-React专门设计的简易全局状态管理器

同时兼容React

使用方法

  1. npm install lzy-ruzy
  2. new Ruzy(...initStates)
  3. store.useState
  4. store.setState
// ----------创建一个store,初始化states
import Ruzy from 'lzy-ruzy'

export default new Ruzy({
    name: '张三',
    age: 18
})

// ------------页面
import store from './store'

function Child(){
    return (<div>age:{age} name:{name}</div>)
}

function App(){
    const { name, age } = store.useState('name', 'age')

    const addAge = () => { store.setState({ age: age + 1 })
    const changeName = () => { store.setState({ name: '李四' }) }

    return(
         <div>

            <button onClick={addAge}>全局age++</button>
            <button onClick={changeName}>全局name改变</button>

            <Child />
            <Child />
            <Child />
         </div>
    )
}
1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago