Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
KamyarTaher authored Jul 27, 2024
1 parent 1517a62 commit 3f3a00b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,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.
// Select a state
const { age } = useSelectors('user.age');
// You can simply select as many state you want
// You can select as many state you want
const { name, theme } = useSelectors('user.name', 'settings.theme');
// 'user.name' and 'settings.theme' are inferred as strings, then name and theme will be suggested
// 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');
// 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 @@ -104,8 +104,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 3f3a00b

Please sign in to comment.