You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+100-1Lines changed: 100 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -479,7 +479,7 @@ export default view(() => {
479
479
**Local stores in functions rely on React hooks. They require React and React DOM v16.8+ or React Native v0.59+ to work.**
480
480
481
481
<details>
482
-
<summary>You can use any React hook - including <code>useState</code> - in function components, Easy State won't interfere with them.</summary>
482
+
<summary>You can use React hooks - including <code>useState</code> - in function components, Easy State won't interfere with them. Please use [autoEffect](#local-auto-effects-in-function-components) instead of the `useEffect` hook for the best experience though.</summary>
483
483
<p></p>
484
484
485
485
```jsx
@@ -623,6 +623,105 @@ Instead of returning an object, you should directly mutate the received stores.
623
623
624
624
</details>
625
625
626
+
### Adding side effects
627
+
628
+
Use `autoEffect` to react with automatic side effect to your store changes. Auto effects should contain end-of-chain logic - like changing the document title or saving data to LocalStorage. `view` is a special auto effect that does rendering.
629
+
630
+
<details>
631
+
<summary>Never use auto effects to derive data from other data. Use dynamic getters instead.</summary>
// this won't update the document title, the effect is cleared
665
+
app.name='My App'
666
+
```
667
+
668
+
#### Local auto effects in function components
669
+
670
+
Use local auto effects in function components instead of the `useEffect` hook when reactive stores are used inside them. These local effects are automatically cleared when the component unmounts.
<summary>Explicitly pass none reactive dependencies - like vanillas props and state - to local auto effects in function components.</summary>
685
+
<p></p>
686
+
687
+
Because of the design of React hooks you have to explicitly pass all none reactive data to a hook-like dependency array. This makes sure that the effect also runs when the none reactive data changes.
0 commit comments