Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/chempogonzalez/cervello

🀯 Simplest and trully reactive state manager for React
https://github.com/chempogonzalez/cervello

Last synced: 4 months ago
JSON representation

🀯 Simplest and trully reactive state manager for React

Awesome Lists containing this project

README

        

# Cervello

[![npm version](https://img.shields.io/npm/v/@cervello/react?color=blue&style=flat-square)](https://www.npmjs.com/package/@cervello/react)
[![bundle-size](https://img.shields.io/bundlephobia/minzip/@cervello/react/latest?color=orange&style=flat-square)](https://bundlephobia.com/package/@cervello/react@latest)



> 🀯 Simplest and truly reactive state manager for React _(just 1.5kb)_






πŸ“– Documentation website



## πŸš€ **Features**

- βš›οΈ Truly reactive on store change like normal objects without functions **_(nested properties too πŸš€!!)_**
- βœ… Super simple and minimalistic API
- 🐨 Listen properties lazily
- πŸ‘Œ No unnecessary re-renders
- πŸ”’ Immutable changes
- πŸ”‘ Typescript support

## πŸ“¦ **Install**

```bash
# NPM
npm install @cervello/react

# PNPM
pnpm add @cervello/react

# YARN
yarn add @cervello/react
```

## πŸ’» **Quick Usage**

The `cervello` function allows you to create a new store in an easy way.
Just set the initial value _`(the type will be inferred based on this value)`_ and you have it!

```ts
// - store-example.ts
import { cervello } from '@cervello/react'

export const {
store, // Reactive store object
useStore, // Hook to listen for store changes
useSelector, // Hook to listen for changes on parts of the store
reset, // Function to reset the store to initial value
} = cervello({
count: 0,
isModalOpen: false,
/* ... */
})

// With the store object you can use it outside of React components
const increment = () => { store.count++ }

const Button = () => {
const { count } = useStore() // Listen for changes on the whole store
return (

{count}

)
}

const ButtonWithSelector = () => {
const { count } = useSelector(['count']) // Listen for changes just on 'count' property
return (

{count}

)
}
```




---------

### To see more in depth explanations or API references and more examples: πŸ“– [Documentation website](https://www.cervello.dev)

--------


> Created with Typescript! ⚑ and latin music 🎺🎡