Skip to content

Commit

Permalink
fix(ssr): useLayoutEffect -> useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrayZoneYour committed Nov 16, 2021
1 parent 5621226 commit ecb69f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-model",
"version": "4.1.4",
"version": "4.2.0-rc.2",
"description": "The State management library for React",
"main": "./dist/react-model.js",
"module": "./dist/react-model.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion src/helper.ts
Expand Up @@ -91,7 +91,7 @@ const getInitialState = async <T extends { modelName: string | string[] }>(
const ServerState: { [name: string]: any } = { __FROM_SERVER__: true }
await Promise.all(
Object.keys(Global.State).map(async (modelName) => {
let prefix = config?.prefix || ''
let prefix = (config && config.prefix) || ''
if (
!context ||
!context.modelName ||
Expand Down
13 changes: 11 additions & 2 deletions src/index.tsx
Expand Up @@ -3,7 +3,13 @@
import produce, { enableES5 } from 'immer'
enableES5()
import * as React from 'react'
import { PureComponent, useLayoutEffect, useState, useRef } from 'react'
import {
PureComponent,
useLayoutEffect,
useEffect,
useState,
useRef
} from 'react'
import Global from './global'
import {
Consumer,
Expand All @@ -14,6 +20,9 @@ import {
} from './helper'
import { actionMiddlewares, applyMiddlewares, middlewares } from './middlewares'

const useStoreEffect =
typeof window === 'undefined' ? useEffect : useLayoutEffect

const isModelType = (input: any): input is ModelType => {
return (input as ModelType).state !== undefined
}
Expand Down Expand Up @@ -360,7 +369,7 @@ const useStore = (modelName: string, selector?: Function) => {
const usedSelector = isFromCreateStore ? mutableState.selector : selector
const usedState = isFromCreateStore ? mutableState : getState(modelName)

useLayoutEffect(() => {
useStoreEffect(() => {
Global.uid += 1
const local_hash = '' + Global.uid
hash.current = local_hash
Expand Down

0 comments on commit ecb69f8

Please sign in to comment.