Skip to content

[docs] react in jsx scope #42169

Open
Open
@oliviertassinari

Description

@oliviertassinari

Summary

SCR-20240906-ofzf

https://mui.com/material-ui/react-button/#basic-button

See the:

import * as React from 'react';

What is this for? Since React 17.0.0 https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#removing-unused-react-imports and the introduction of a new JSX transform, the import of React doesn't no longer need to be in the scope. We don't support older versions now:

"react": "^17.0.0 || ^18.0.0 || ^19.0.0",

So most of the demos in the docs could be written without the import of React. This would be simpler. It's actually a DX problem because of https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md.

  • Vite (latest version) warns when starting a new project and copying and pasting our demos in the docs:
SCR-20240511-oeqy
  • Next.js (latest version) doesn't say anything, it's happy with having import * as React from 'react' or not having it.

Examples

They don't have those imports:

Motivation

In the past, we didn't make the change because there were too many React users <17.0.0. But this seems to be mostly OK now:

SCR-20240906-opdn

https://tools-public.mui.com/prod/pages/npmVersion?package=react

I assume that all bundlers use the new JSX transform.

Context

Related a bit to #38966.

Metadata

Metadata

Assignees

Labels

docsImprovements or additions to the documentationdxRelated to developers' experience

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions