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.

Unknown prop `staticContext`

See original GitHub issue

It looks like the recent change to add staticContext to the prop types has the unintended consequence of passing undefined outside of StaticRouter.

const MyCmp = withRouter(function({ match, location, history, children, ...props }) {
  return <div {...props}></div>;
});

I’m not 100% of my diagnosis but it seems close, any ideas?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
matthewrobbcommented, Mar 11, 2017

It may be that people will need to adjust to filter out staticContext but it introduced a bug for me where my assumption was that the only props is be getting from withRouter were match location and history. So that assumption falls over when I want to pass every other prop on to a regular Dom element. I’m now inadvertantly passing an undefined staticContext prop.

Yes I can and now am filtering it out but its existence was unexpected since I’m not using a static router.

3reactions
matthewrobbcommented, Mar 10, 2017

Is there no way to omit the prop from being passed when not in a static router? It seems like an edge detail that most users will have to guard against without having any idea why. If it’s only on the passed in context/props when present the end result for the guards stays the same and destructured {staticContext} will remain undefined. The only difference is that object rest will not pick it up. Maybe the problem lies there. I almost feel like Object Rest shouldn’t bring over undefined properties at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unknown prop `staticContext` · Issue #4683 - GitHub
Is there no way to omit the prop from being passed when not in a static router? It seems like an edge detail...
Read more >
React does not recognize the `staticContext` prop on a DOM ...
The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as...
Read more >
unknown prop warning, styled-components unknown prop, react ...
The unknown-prop warning will fire if you attempt to render a DOM element ... Warning: React does not recognize the staticContext prop on...
Read more >
[Solved]-React Unknown Prop 'onSearch'-Reactjs
Coding example for the question React Unknown Prop 'onSearch'-Reactjs. ... React wrapper: React does not recognize the `staticContext` prop on a DOM element ......
Read more >
React does not recognize the `staticContext` prop on a DOM ...
I'm trying to create a wrapper component around the react-router-dom NavLink component. I would like my custom component to accept all of NavLinks...
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