Skip to content

Commit

Permalink
remove useLayoutEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
IpShot committed Jul 10, 2020
1 parent 87194c3 commit 0cef400
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/flexReducer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useRef, useEffect, useLayoutEffect } from 'react';
import { useState, useRef, useEffect } from 'react';
import { unstable_batchedUpdates as batch } from './utils/batch';
import shallowEqual from './utils/shallowEqual';

Expand All @@ -12,11 +12,6 @@ const context = {

Object.seal(context);

// We use useEffect for server side rendering
const useFlexEffect = typeof window !== 'undefined'
? useLayoutEffect
: useEffect;

function callReducerDispatch(disp, action) {
const { reducerName, reducer, render } = disp;
const state = context.state[reducerName];
Expand Down Expand Up @@ -81,7 +76,7 @@ export function useFlexReducer(reducerName, reducer, initialState, options = { c
});
}

useFlexEffect(() => {
useEffect(() => {
return () => {
if (options.cache && !cache[reducerName]) cache[reducerName] = lastState;
delete context.state[reducerName];
Expand Down Expand Up @@ -124,7 +119,7 @@ export function useSelector(selector, equalityFn = refEquality) {
context.dispatch.set(key.current, { selector, equalityFn, result, render });
}

useFlexEffect(() => {
useEffect(() => {
return () => context.dispatch.delete(key.current);
}, [key.current, context.dispatch]);

Expand Down

0 comments on commit 0cef400

Please sign in to comment.