profile
viewpoint

Ask questionsFunction components do not support contextType.

<!-- Note: if the issue is about documentation or the website, please file it at: https://github.com/reactjs/reactjs.org/issues/new -->

Do 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.

facebook/react

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.

useful!

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
source:https://uonfu.com/
Github User Rank List