Closed
Description
Initial checklist
- I read the support docs
- I read the contributing guide
- I agree to follow the code of conduct
- I searched issues and couldn’t find anything (or linked relevant results below)
Affected packages and versions
@mdx-js/react 3.0.1
Link to runnable example
No response
Steps to reproduce
I reproduced this problem faily easily with Docusaurus as explained here:
The answer of Josh shows how to reproduce the probelm using mdx-js loader. They sent me over to you as it seem the root cause sits in mdx-js.
Expected behavior
It should be possible declare React class components in MDX files without errors.
Actual behavior
When you try to declare react components using React.Component in MDX files you end up with an Invalid hook call. error.
- Setup an empty Docusuarus with latest dependencies
- npx create-docusaurus@latest my-website classic --typescript && npx ncu -u && npm i && npm start
- Open https://docusaurus.new/stackblitz-ts
- Open the
docs/tutorial-basics/markdown-features.mdx
- Change the file content to
---
sidebar_position: 4
---
import React from 'react'
export class Test extends React.Component {
render() {
return (<div>Title</div>);
}
}
<Test />
- Open the page in the browser.
- Experience the error.
Runtime
Node v20
Package manager
npm v10
OS
Windows
Build and bundle tools
Docusaurus