Skip to content

Commit

Permalink
test: more utils
Browse files Browse the repository at this point in the history
  • Loading branch information
iamogbz committed Sep 13, 2020
1 parent 4057889 commit e6bd9b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/components/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export function Provider<S, T extends string, P>({
);

const value = React.useMemo<ContextValue<S, T, P>>(
() => ({ ...enhanced, state }),
function getValue() {
return { ...enhanced, state };
},
[enhanced, state],
);

Expand Down
7 changes: 6 additions & 1 deletion src/hooks/useSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ export function useSelector<S, R, T extends string, P>(
Context?: Context<S, T, P>,
): R | undefined {
const { state } = React.useContext(Context ?? GlobalContext);
return React.useMemo(() => selector?.(state), [selector, state]);
return React.useMemo(
function select() {
return selector?.(state);
},
[selector, state],
);
}
9 changes: 5 additions & 4 deletions tests/__mocks__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function createMocks(): {
const Context = createContext(
rootDuck.reducer,
rootDuck.initialState,
undefined,
applyMiddleware(),
"GlobalContext",
true,
);
Expand Down Expand Up @@ -108,10 +108,11 @@ export function createMocks(): {
dispatch({ type: "SOME_ACTION" });
return () => (action): typeof action => action;
};
const emptyRootDuck = createRootDuck();
const ErrorContext = createContext(
rootDuck.reducer,
rootDuck.initialState,
applyMiddleware(badMiddleware),
emptyRootDuck.reducer,
emptyRootDuck.initialState,
applyMiddleware(logger, badMiddleware),
"ErrorContext",
);

Expand Down

0 comments on commit e6bd9b4

Please sign in to comment.