0.1.22 • Published 4 months ago
@e-state/react v0.1.22
@e-state/react
Estate is a React state management library designed for simplicity and ease of use.
Installation
npm install @e-state/react
# or
yarn add @e-state/react
Getting Started
First, you need to initialize module and export a hook.
export const { useEstate, clearEstate } = createEstate<{
main: { drawer: boolean; items: { title: string; id: string }[] };
sub: { title: string; name: string };
}>(
{
main: {
drawer: false,
items: [],
},
sub: {
title: "",
name: "",
},
},
{
persist: ["sub"],
}
);
Then, you can import and use it in your React client components.
"use client";
import { clearEstate, useEstate } from "../utils/estate";
export default function Page() {
const { drawer, setEstate } = useEstate("main");
return (
<>
{drawer && <Drawer />}
<button
onClick={() => {
setEstate({ drawer: (currentValue) => !currentValue });
}}
>
{drawer ? "Close Drawer" : "Open Drawer"}
</button>
<button
onClick={() => {
clearEstate("main");
}}
>
Initialize main state
</button>
</>
);
}
Key Features
- Easy Setup: You can set up global state management with minimal configuration. No need to wrap your entire project in a provider, and only one initialization function is required.
- Minimal Boilerplate: With just two lines of code in each file, you can both retrieve and modify the state, reducing the amount of code you need to write.
- Strong Typing: Benefit from full type inference for state retrieval and updates, ensuring a safe and straightforward development experience.
Notes
When using persistence with Next.js, keep in mind that server-side rendering won't have access to the persisted data, so the initial values will be displayed for a moment after page load.
0.1.22
4 months ago
0.1.21
4 months ago
0.1.20
4 months ago
0.1.19
4 months ago
0.1.17
5 months ago
0.1.18
5 months ago
0.1.14
5 months ago
0.1.15
5 months ago
0.1.16
5 months ago
0.1.11
5 months ago
0.1.12
5 months ago
0.1.13
5 months ago
0.1.10
5 months ago
0.1.9
5 months ago
0.1.8
6 months ago
0.1.7
6 months ago
0.1.5
6 months ago
0.1.4
6 months ago
0.1.3
6 months ago
0.1.2
6 months ago
0.1.1
6 months ago
0.1.0
6 months ago