mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
94.03k stars 32.31k forks source link

[docs] react in jsx scope #42169

Open oliviertassinari opened 6 months ago

oliviertassinari commented 6 months ago

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:

https://github.com/mui/material-ui/blob/44e3ce3034de19f81aaec36c7a866cf9d45d9885/packages/mui-material/package.json#L82

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.

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.

brijeshb42 commented 6 months ago

Agreed. We can atleast start with our own docs, update the eslint rules, and then update the examples.

oliviertassinari commented 2 months ago

cc @colmtuite @aarongarciah @joserodolfofreitas @samuelsycamore it looks like it's a no-brainer to deploy this change in all our demos, e.g.

-import * as React from 'react';
 import Stack from '@mui/material/Stack';
 import Button from '@mui/material/Button';

 export default function BasicButtons() {
   return (
     <Stack spacing={2} direction="row">
       <Button variant="text">Text</Button>
       <Button variant="contained">Contained</Button>
       <Button variant="outlined">Outlined</Button>
     </Stack>
   );
 }