Function components do not support contextType.
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What is the current behavior?
Warning: withRouter(RegisterModal): Function components do not support contextType.
What is the expected behavior?
No error
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
16.6.0
https://codesandbox.io/s/01zl4m022v
Unfortunately, I’m unable to reproduce this in codesandbox…
import React, { Component } from "react";
import { withRouter } from "react-router-dom";
import ErrorContext from "./ErrorContext";
class RegisterModal extends Component {
render() {
return <div>test</div>;
}
}
RegisterModal.contextType = ErrorContext;
// this doesn't cause any error:
// export default RegisterModal;
// this causes an error:
export default withRouter(RegisterModal);
For some reason, whenever I wrap my RegisterModal component with withRouter, I get this error: Warning: withRouter(RegisterModal): Function components do not support contextType.
. The weird thing is I’m setting contextType directly on the class, before the HOC function is applied.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Function components do not support contextType
I encountered an issue when trying to add context to a React component that was wrapped with a React Router withRouter(...) function. import ......
Read more >Warning when using withRouter with new React Context API
Warning: withRouter(Home ): Function components do not support contextType. This happens when use the React context API like this
Read more >Context | React
Stateless functional components are also able to reference context if contextTypes is defined as a property of the function. The following code shows...
Read more >React's Context API Tutorial: What Context is and How to use it!
While this solution does work, problems begin if a component on a different ... I have Warning: Image: Function components do not support...
Read more >contextType property of a React component ... - DeepScan
createContext() are assigned to the contextType property. Note that you should use the context object itself, not the Consumer or Provider ...
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
was usings contextType = ThemeContext for example on my component as context api suggests, was on react 16.6.1 and it still had this issue…
Yes, the issue persists even after updating hoist-non-react-statics. See the issue discussed here