Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/KamyarTaher/zust
Browse files Browse the repository at this point in the history
  • Loading branch information
KamyarTaher committed Jul 28, 2024
2 parents 9abb753 + 6126913 commit 86b1fda
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

A lightweight state management library using Zustand. Zust provides a simple API and a minimalistic approach for managing the application state.

⚠ WARNING, PACKAGE IS NOT WORKING YET. BUT YOU CAN CLONE THE REPO AND USE ZUST TO TEST IT! ⚠
## Live Example

Check out this interactive example on CodeSandbox to see Zust in action:

⚠ Package not working yet..

[Open CodeSandbox Example](https://codesandbox.io/p/sandbox/zust-playground-34lrrp)

## Table of Contents
Expand Down Expand Up @@ -50,15 +53,17 @@ const initialState = {
// Create the store
const { useSelectors, setDeep } = createStore(initialState);

// Example of using selectors
function ExampleComponent() {
// Automatic type inference and path suggestion for all functions' input and output
// 'user.name' and 'settings.theme' are inferred as strings, then name and theme will be suggested
// Select a state
const { age } = useSelectors('user.age');
// You can select as many state you want
const { name, theme } = useSelectors('user.name', 'settings.theme');
// All input path string are suggested by the IDE and are strongly typed, making the selection easy and safe
// The same goes for the destructured object returned, only the selected state will be suggested

// Update state at any depth just by specifying the path
// Update a state at any depth directly by specifying the path
const onClick1 = () => setDeep('user.name', 'Jane');
// Also, you can have access to the current state and return a new one
// You have to the current state
const onClick2 = () => setDeep('settings.theme', (prev) => prev === 'light' ? 'dark' : 'light');

return (
Expand Down Expand Up @@ -102,8 +107,6 @@ function ExampleComponent() {
return (
<div>
<p>User Name: {name}</p>
<p>Second User Name: {secondName}</p>
<p>Theme: {theme}</p>
<button onClick={onClick}>Update User Name</button>
</div>
);
Expand Down

0 comments on commit 86b1fda

Please sign in to comment.