New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(v2): unclear if React classes are supported in mdx or only functions #2612
Comments
|
@nainardev advised me to use a function together with the |
|
Hey @benmccann it seems that this problem is not related with Docusaurus, so maybe it's better report this issue in For help to solve this problem, you can show more about your implementation, the problem can be related to other definitions in your code. |
|
Sure. Here's an example of where we're doing this: https://raw.githubusercontent.com/chartjs/Chart.js/master/docs/docs/charts/line.mdx |
|
Not sure how to document this. We can do many things in MDX and it's difficult to document all of them in an exhaustive way. For example: # Hello
import MyComponent from "@site/src/components/MyComponent"
<MyComponent />Declaring components inline (class or function) should work but you are more likely to make a typo and have a cryptic error message, and your IDE won't help you much. MDX has its own limitations and bugs too In general, you can validate how MDX transform your mdx doc to a React component using https://mdxjs.com/playground If it looks like a valid JS component, it should work, otherwise try to fix the errors. |


I'm attempting to migrate the documentation for the popular Chart.js library from GitBook to Docusaurus 2. I created an
.mdxwith the following contents :It gives me the error:
If I simply remove
componentDidMountthen it worksIs there some restriction on the types of React components that I'm missing? I don't see anything mentioned in the documentation. The documentation only gives an example of a function component and does not show usage of a class component, so I'm wondering if that's not supported?
I'm a React beginner. I'm trying to create a new Chart.js instance, which needs a reference to the DOM element where the Chart will be rendered and so I'm trying to do it in
componentDidMountafter creating the DOM element inrenderHave you read the Contributing Guidelines on issues?
Yes
The text was updated successfully, but these errors were encountered: