Skip to content

Commit

Permalink
implement deps on useDispatchWithMap
Browse files Browse the repository at this point in the history
This more closely mirrors the original behaviour of withDispatch.
  • Loading branch information
nerrad committed Jun 1, 2019
1 parent 50e8a70 commit 6946a6a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ const useIsomorphicLayoutEffect =
* the first argument and the `registry` object
* as the second argument. Should return an
* object mapping props to functions.
* @param {Array} deps An array of dependencies for the hook.
* @return {Object} An object mapping props to functions created by the passed
* in dispatchMap.
*/
const useDispatchWithMap = ( dispatchMap ) => {
const useDispatchWithMap = ( dispatchMap, deps ) => {
const registry = useRegistry();
const currentDispatchMap = useRef( dispatchMap );

Expand All @@ -64,7 +65,7 @@ const useDispatchWithMap = ( dispatchMap ) => {
.current( registry.dispatch, registry )[ propName ]( ...args );
}
);
}, [ dispatchMap, registry ] );
}, [ registry, ...deps ] );
};

export default useDispatchWithMap;
2 changes: 1 addition & 1 deletion packages/data/src/components/with-dispatch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const withDispatch = ( mapDispatchToProps ) => createHigherOrderComponent(
ownProps,
registry
);
const dispatchProps = useDispatchWithMap( mapDispatch );
const dispatchProps = useDispatchWithMap( mapDispatch, [] );
return <WrappedComponent { ...ownProps } { ...dispatchProps } />;
}
),
Expand Down

0 comments on commit 6946a6a

Please sign in to comment.