Ask questionsFunction components do not support contextType.

<!-- Note: if the issue is about documentation or the website, please file it at: -->

Do you want to request a feature or report a 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?


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.


Answer questions techyrajeev

Is there any solution to this issue? I just updated to 16.6.0 but still facing this issue. Please suggest any possible working solution.


Related questions

Disable react strict mode on third party libraries hot 7
Warning: Unknown DOM property for. Did you mean htmlFor? hot 6
TypeError: Object(...) is not a function
Refs - &#34;object is not extensible&#34;
React@16.9 block `javascript:void(0);`
Warning: validateDOMNesting(...): <tr> cannot appear as a child of <table> hot 3
"DevTools v4 is incompatible with this version of React" with React Native & latest version of React hot 3
Feedback on useEffect depndencies change error hot 3
[ESLint] Feedback for 'exhaustive-deps' lint rule hot 3
React custom hook "Should have a queue. This is likely a bug in React" error message. hot 2
useEffect causes 'callback is not a function' exception hot 2
DevTools: Updating state or props in devtools does not trigger component update. hot 2
Infinite loop in useEffect using blank object or array hot 2
Error on unit test : Cannot read property 'Symbol(Symbol.iterator)' of undefined hot 2
False-positive security precaution warning (`javascript:` URLs) hot 2
Github User Rank List