question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can't use hooks inside of component.

See original GitHub issue

I’m experimenting with the library ( Great effort by the way ). however I’m somehow unable to use React.useContext inside of screen component.

Screen Shot 2020-10-25 at 1 51 50 PM

export const stateNavigator = new StateNavigator([
  {key: 'hello'},
  {key: 'world', trackCrumbTrail: true},
]);

const {states} = stateNavigator;

states.hello.renderScene = Hello;
states.world.renderScene = World;

function Hello(){
  React.useContext(...)
  ///
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
a-eidcommented, Oct 25, 2020

@grahammendick thank you.

1reaction
grahammendickcommented, Oct 25, 2020

This is what you’re after

states.hello.renderScene = () => <Hello />;

function Hello() {
  const {stateNavigaton} = React.useContext(NavigationContext);

  return null;  //
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid Hook Call Warning - React
Hooks can only be called inside the body of a function component. There are three common reasons you might be seeing it: You...
Read more >
React hooks - Can't use hook inside plain async function?
Hooks can only be called inside the top level of the body of a function component. Read the official documentation. Share.
Read more >
You Can't Call Hooks Inside Conditions? Yes you can
Calling hooks conditionally breaks the rules, yes. Wrap the hook with a component and render that component optionally to toggle the usage of ......
Read more >
Invalid hook call. Hooks can only be called inside the body of ...
The error "Invalid hook call. Hooks can only be called inside the body of a function component" occurs for multiple reasons, having a...
Read more >
"Hooks can only be called inside the body of a function ...
"Hooks can only be called inside the body of a function component" ReactJS Error · You may have mismatching versions of React and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found