Skip to content

Commit

Permalink
Added missing nextHook() call to react-debug-tools useContext() impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Feb 24, 2019
1 parent ba708fa commit d8b9115
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Expand Up @@ -93,6 +93,7 @@ function useContext<T>(
context: ReactContext<T>,
observedBits: void | number | boolean,
): T {
nextHook();
hookLog.push({
primitive: 'Context',
stackError: new Error(),
Expand Down
Expand Up @@ -427,4 +427,20 @@ describe('ReactHooksInspectionIntegration', () => {
expect(setterCalls[0]).not.toBe(initial);
expect(setterCalls[1]).toBe(initial);
});

// This test case is based on an open source bug report:
// facebookincubator/redux-react-hook/issues/34#issuecomment-466693787
it('should properly advance the current hook for useContext', () => {
const MyContext = React.createContext(123);

function Foo(props) {
React.useContext(MyContext);
const [data] = React.useState({foo: 'abc'});
return <div>foo: {data.foo}</div>;
}

const renderer = ReactTestRenderer.create(<Foo />);
const childFiber = renderer.root._currentFiber();
ReactDebugTools.inspectHooksOfFiber(childFiber);
});
});

0 comments on commit d8b9115

Please sign in to comment.