Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xiaofan2406/ryze
https://github.com/xiaofan2406/ryze
react state-management
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/xiaofan2406/ryze
- Owner: xiaofan2406
- License: mit
- Created: 2020-05-27T06:48:32.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-13T22:32:25.000Z (about 2 months ago)
- Last Synced: 2024-12-13T23:25:12.598Z (about 2 months ago)
- Topics: react, state-management
- Language: JavaScript
- Homepage:
- Size: 700 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ryze
A minimal state management library for React.
## Install
```bash
npm install ryze
```## Example
```jsx
import {createStore} from 'ryze';const {store, useSlice} = createStore({count: 10, todos: []});
const Counter = () => {
const count = useSlice('count');return (
count: {count}
{
store.setState((prev) => ({...prev, count: prev.count + 1}));
}}
>
Add
);
};const getActiveTodos = (state) => state.todos.filter((item) => !item.completed);
const Todos = () => {
const todos = useSlice(getActiveTodos);return (
{todos.map((todo) => (
- {todo.title}
))}
{
store.setState((prev) => ({
...prev,
todos: [...prev.todos, {title: 'New Todo', date: +new Date()}],
}));
}}
>
Add
);
};const Example = () => {
return (
<>
>
);
};
```## Constraints
### Selectors
Selector passed to `useSlice` should have the same identity across re renders.
That is,
- either declare selectors outside of components, or
- if the selector is dependent on component props, use `useCallback` to ensure the selector only changes when the prop change.### Updates
Updates should be immutable. Return new values, rather than modify the state value directly.