Skip to content

Commit ecb69f8

Browse files
committed
fix(ssr): useLayoutEffect -> useEffect
1 parent 5621226 commit ecb69f8

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-model",
3-
"version": "4.1.4",
3+
"version": "4.2.0-rc.2",
44
"description": "The State management library for React",
55
"main": "./dist/react-model.js",
66
"module": "./dist/react-model.esm.js",

src/helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const getInitialState = async <T extends { modelName: string | string[] }>(
9191
const ServerState: { [name: string]: any } = { __FROM_SERVER__: true }
9292
await Promise.all(
9393
Object.keys(Global.State).map(async (modelName) => {
94-
let prefix = config?.prefix || ''
94+
let prefix = (config && config.prefix) || ''
9595
if (
9696
!context ||
9797
!context.modelName ||

src/index.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import produce, { enableES5 } from 'immer'
44
enableES5()
55
import * as React from 'react'
6-
import { PureComponent, useLayoutEffect, useState, useRef } from 'react'
6+
import {
7+
PureComponent,
8+
useLayoutEffect,
9+
useEffect,
10+
useState,
11+
useRef
12+
} from 'react'
713
import Global from './global'
814
import {
915
Consumer,
@@ -14,6 +20,9 @@ import {
1420
} from './helper'
1521
import { actionMiddlewares, applyMiddlewares, middlewares } from './middlewares'
1622

23+
const useStoreEffect =
24+
typeof window === 'undefined' ? useEffect : useLayoutEffect
25+
1726
const isModelType = (input: any): input is ModelType => {
1827
return (input as ModelType).state !== undefined
1928
}
@@ -360,7 +369,7 @@ const useStore = (modelName: string, selector?: Function) => {
360369
const usedSelector = isFromCreateStore ? mutableState.selector : selector
361370
const usedState = isFromCreateStore ? mutableState : getState(modelName)
362371

363-
useLayoutEffect(() => {
372+
useStoreEffect(() => {
364373
Global.uid += 1
365374
const local_hash = '' + Global.uid
366375
hash.current = local_hash

0 commit comments

Comments
 (0)