https://github.com/robertdp/purescript-react-store
An async state reducer hook for React. Bring your own execution context. Very likely to be replaced by https://github.com/robertdp/purescript-react-halo
https://github.com/robertdp/purescript-react-store
Last synced: 5 months ago
JSON representation
An async state reducer hook for React. Bring your own execution context. Very likely to be replaced by https://github.com/robertdp/purescript-react-halo
- Host: GitHub
- URL: https://github.com/robertdp/purescript-react-store
- Owner: robertdp
- Created: 2020-04-22T06:02:11.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-11T02:51:24.000Z (over 3 years ago)
- Last Synced: 2025-05-13T14:34:56.591Z (about 1 year ago)
- Language: PureScript
- Homepage:
- Size: 64.5 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# purescript-react-store
Asynchronous state management made easy(er).
This library provides the hook `useStore` for `react-basic-hooks`. It offers a straightforward and convenient approach to asynchronous state management for components.
```purs
useStore ::
forall m props state action.
MonadEffect m =>
{ props :: props
, init :: state
, update ::
{ props :: props
, state :: state
, setState :: (state -> state) -> m Unit
, readProps :: m props
, readState :: m state
} ->
action ->
m Unit
, launch :: m Unit -> Aff Unit
} ->
Hook (UseStore props state action m)
{ state :: state
, dispatch :: action -> Effect Unit
, readState :: Effect state
}
```
`useStore` is most useful for larger and more complex components, like page-level components. If you're not sure you need this library, try the hooks exposed by `react-basic-hooks` first. Just using `useEffect` and `useReducer` can get you a long way, and that library also includes `useAffReducer` for an Elm-ish approach.