-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
"@udecode/zustood": minor | ||
--- | ||
|
||
`react-tracked` support | ||
|
||
Use the tracked hooks in React components, no providers needed. Select your | ||
state and the component will trigger re-renders only if the **accessed property** is changed. Use the `useTracked` method: | ||
|
||
```tsx | ||
// Global tracked hook selectors | ||
export const useTrackedStore = () => mapValuesKey('useTracked', rootStore); | ||
|
||
// with useTrackStore UserEmail Component will only re-render when accessed property owner.email changed | ||
const UserEmail = () => { | ||
const owner = useTrackedStore().repo.owner() | ||
return ( | ||
<div> | ||
<span>User Email: {owner.email}</span> | ||
</div> | ||
); | ||
}; | ||
// with useStore UserEmail Component re-render when owner changed, but you can pass equalityFn to avoid it. | ||
const UserEmail = () => { | ||
const owner = useStore().repo.owner() | ||
// const owner = useStore().repo.owner((prev, next) => prev.owner.email === next.owner.email) | ||
return ( | ||
<div> | ||
<span>User Email: {owner.email}</span> | ||
</div> | ||
); | ||
}; | ||
``` |