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
+101Lines changed: 101 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,6 +82,8 @@ npm install react-model
82
82
-[How can I disable the console debugger?](#how-can-i-disable-the-console-debugger)
83
83
-[How can I add custom middleware](#how-can-i-add-custom-middleware)
84
84
-[How can I make persist models](#how-can-i-make-persist-models)
85
+
-[How can I deal with local state](#how-can-i-deal-with-local-state)
86
+
-[actions throw error from immer.module.js](#actions-throw-error-from-immer.module.js)
85
87
86
88
## Core Concept
87
89
@@ -750,3 +752,102 @@ Model({ Example }, JSON.parse(localStorage.getItem('__REACT_MODEL__')))
750
752
```
751
753
752
754
[⇧ back to top](#table-of-contents)
755
+
756
+
### How can I deal with local state
757
+
758
+
What should I do to make every Counter hold there own model? 🤔
759
+
760
+
```tsx
761
+
classAppextendsComponent {
762
+
render() {
763
+
return (
764
+
<divclassName="App">
765
+
<Counter />
766
+
<Counter />
767
+
<Counter />
768
+
</div>
769
+
)
770
+
}
771
+
}
772
+
```
773
+
774
+
<details>
775
+
<summary>Counter model</summary>
776
+
<p>
777
+
778
+
```ts
779
+
interfaceState {
780
+
count: number
781
+
}
782
+
783
+
interfaceActionParams {
784
+
increment: number
785
+
}
786
+
787
+
constmodel:NextModelType<State, ActionParams> = {
788
+
state: {
789
+
count: 0
790
+
},
791
+
actions: {
792
+
increment: payload=> {
793
+
// immer.module.js:972 Uncaught (in promise) Error: An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft
0 commit comments