Unknown prop `staticContext`
See original GitHub issueIt 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:
- Created 7 years ago
- Reactions:1
- Comments:11 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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.