Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xiaofan2406/ryze


https://github.com/xiaofan2406/ryze

react state-management

Last synced: about 2 months ago
JSON representation

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.