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: src/store.js
+8-3Lines changed: 8 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,9 @@ import { observable } from '@nx-js/observer-util';
3
3
4
4
import{
5
5
isInsideFunctionComponent,
6
-
isInsideClassComponent,
6
+
isInsideClassComponentRender,
7
+
isInsideFunctionComponentWithoutHooks,
7
8
}from'./view';
8
-
import{hasHooks}from'./utils';
9
9
10
10
exportfunctionstore(obj){
11
11
// do not create new versions of the store on every render
@@ -14,10 +14,15 @@ export function store(obj) {
14
14
if(isInsideFunctionComponent){
15
15
returnuseMemo(()=>observable(obj),[]);
16
16
}
17
-
if(!hasHooks&&isInsideClassComponent){
17
+
if(isInsideFunctionComponentWithoutHooks){
18
18
thrownewError(
19
19
'You cannot use state inside a function component with a pre-hooks version of React. Please update your React version to at least v16.8.0 to use this feature.',
20
20
);
21
21
}
22
+
if(isInsideClassComponentRender){
23
+
thrownewError(
24
+
'You cannot use state inside a render of a class component. Please create your store outside of the render function.',
0 commit comments