ReactMasters / state-manager

상태관리 라이브러리
MIT License
0 stars 0 forks source link

문서와 라이센스 추가 #28

Closed JeGwan closed 2 weeks ago

JeGwan commented 2 weeks ago

@react-masters/state-manager

k-state library under 2KB

Getting Started

Installation

npm install @react-master/state-manager
yarn add @react-master/state-manager
pnpm add @react-master/state-manager

API

// Create store
const store = createStore(0 /* initial value */, (set) => {
  /* custom action api */
  return {
    increment: () => set((n) => n + 1),
    decrement: () => set((n) => n + 1),
  }
})

// Use reactive state
const App = () => {
  const count = useReactive(store)

  return (
    <>
      <button onClick={() => store.setState((n) => n + 1)}>plus</button>
      <span>{count}</span>
      <button onClick={() => store.setState((n) => n - 1)}>minus</button>

      {/* Use custom api */}
      <button onClick={() => store.increment()}>increment</button>
    </>
  )
}

// Get current state by store ref without re-render (like ref.current)
const App = () => {
  useEffect(() => {
    store.getState()
  }, [])

  // ...
}

Contributors

We welcome contributions from the community! Feel free to submit pull requests or open issues to help improve the project.

License

This project is licensed under the MIT License - see the LICENSE file for details.