@cervello/react
Version:
π€― Simple, reactive, tiny and performant state-management library
102 lines (71 loc) β’ 2.48 kB
Markdown
# Cervello
[](https://www.npmjs.com/package/@cervello/react)
[](https://bundlephobia.com/package/@cervello/react@latest)
<a href="https://www.cervello.dev">
<img src="https://github.com/chempogonzalez/cervello/blob/main/assets/emoji-logo.png" style="display:block;">
</a>
> π€― Simple, reactive, tiny and performant state-management library for React _(just 1.5kb)_
<br>
<br>
<a href="https://www.cervello.dev">
<p align="center">
<strong>π Documentation website</strong>
</p>
</a>
<br>
## π **Features**
- βοΈ Reactive with store object changes **_(nested properties too π!!)_**
- β
Simple & minimalistic API
- π Batched updates and optimized re-renders
- π¨ Lazy listen nested properties
- π 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! -->
It's **as simple as reassign a new value** to the store properties. <br/>It will notify all the components using `useStore` hook to re-render with the new value.
```ts
// - store-example.ts
import { cervello } from '@cervello/react'
export const {
store, // Object with reactive changes
useStore, // Hook to listen for store or partial store changes
reset, // Function to reset the store to initial value
} = cervello({
fullName: 'Cervello Store',
address: {
city: 'Huelva',
/* ... */
},
})
// Change value from anywhere
store.address.city = 'Sevilla'
// Listen for changes from components
function Address() {
const { address } = useStore()
return (<p>City: {address.city}</p>)
}
// Just listen for changes in the `city` property
const AddressWithSelector = () => {
const { address } = useStore({
select: ['address.city']
})
return (<p>City: {address.city}</p>)
}
```
<br>
<br>
---------
### To see more in depth explanations or API references and more examples: π [Documentation website](https://www.cervello.dev)
--------
<br>
> Created with Typescript! β‘ and latin music πΊπ΅