From b3ab4cfe183fb874643b74df4e80792def55c394 Mon Sep 17 00:00:00 2001 From: Diego Andai Date: Mon, 9 Dec 2024 13:06:05 -0300 Subject: [PATCH] [core] React 19 useRef cleanup (#44704) --- docs/data/joy/components/button-group/SplitButton.tsx | 2 +- docs/data/joy/components/input/DebouncedInput.tsx | 4 +--- docs/data/joy/components/input/InputSlotProps.tsx | 2 +- docs/data/joy/components/snackbar/SnackbarHideDuration.tsx | 2 +- docs/data/joy/components/textarea/TextareaRef.tsx | 2 +- .../material/components/popper/VirtualElementPopper.tsx | 2 +- .../material/components/progress/CircularIntegration.tsx | 2 +- .../material/components/progress/DelayingAppearance.tsx | 4 +--- docs/pages/blog.tsx | 2 +- docs/pages/experiments/joy/style-guide.tsx | 2 +- docs/src/components/header/HeaderNavBar.tsx | 4 ++-- docs/src/components/pricing/PricingTable.tsx | 2 +- docs/src/components/productBaseUI/BaseUICustomization.tsx | 2 +- docs/src/components/productMaterial/MaterialStyling.tsx | 4 ++-- docs/src/modules/components/JoyThemeBuilder.tsx | 6 +++--- packages/mui-base/CONTRIBUTING.md | 2 +- packages/mui-base/src/Button/Button.tsx | 2 +- packages/mui-base/src/FocusTrap/FocusTrap.tsx | 6 +++--- packages/mui-base/src/Tab/Tab.tsx | 2 +- packages/mui-base/src/TextareaAutosize/TextareaAutosize.tsx | 2 +- packages/mui-base/src/unstable_useModal/useModal.ts | 2 +- packages/mui-base/src/useButton/useButton.ts | 2 +- packages/mui-base/src/useDropdown/useDropdown.ts | 2 +- packages/mui-base/src/useSlider/useSlider.ts | 6 +++--- packages/mui-base/src/useSwitch/useSwitch.ts | 2 +- packages/mui-base/src/utils/useControllableReducer.ts | 2 +- packages/mui-base/src/utils/useMessageBus.ts | 2 +- packages/mui-docs/src/Ad/Ad.tsx | 2 +- packages/mui-docs/src/CodeCopy/CodeCopy.tsx | 2 +- packages/mui-docs/src/CodeCopy/useClipboardCopy.ts | 2 +- packages/mui-joy/src/Tab/Tab.tsx | 2 +- packages/mui-joy/src/Tooltip/Tooltip.tsx | 2 +- packages/mui-material/src/Modal/useModal.ts | 2 +- packages/mui-material/src/Popper/BasePopper.tsx | 2 +- packages/mui-material/src/Popper/Popper.spec.tsx | 2 +- packages/mui-material/src/Slider/useSlider.ts | 6 +++--- .../mui-material/src/TextareaAutosize/TextareaAutosize.tsx | 2 +- packages/mui-material/src/Unstable_TrapFocus/FocusTrap.tsx | 6 +++--- packages/mui-material/test/typescript/index.spec.tsx | 4 ++-- packages/mui-utils/src/setRef/setRef.spec.tsx | 2 +- test/integration/material-ui/components.spec.tsx | 2 +- 41 files changed, 54 insertions(+), 58 deletions(-) diff --git a/docs/data/joy/components/button-group/SplitButton.tsx b/docs/data/joy/components/button-group/SplitButton.tsx index 0f7b6521af3dce..52198e2b509d43 100644 --- a/docs/data/joy/components/button-group/SplitButton.tsx +++ b/docs/data/joy/components/button-group/SplitButton.tsx @@ -10,7 +10,7 @@ const options = ['Create a merge commit', 'Squash and merge', 'Rebase and merge' export default function SplitButton() { const [open, setOpen] = React.useState(false); - const actionRef = React.useRef<() => void | null>(null); + const actionRef = React.useRef<() => void>(null); const anchorRef = React.useRef(null); const [selectedIndex, setSelectedIndex] = React.useState(1); diff --git a/docs/data/joy/components/input/DebouncedInput.tsx b/docs/data/joy/components/input/DebouncedInput.tsx index d171661866bf7c..ab8b8d8f6ab5af 100644 --- a/docs/data/joy/components/input/DebouncedInput.tsx +++ b/docs/data/joy/components/input/DebouncedInput.tsx @@ -11,9 +11,7 @@ type DebounceProps = { function DebounceInput(props: InputProps & DebounceProps) { const { handleDebounce, debounceTimeout, ...other } = props; - const timerRef = React.useRef | undefined>( - undefined, - ); + const timerRef = React.useRef>(undefined); const handleChange = (event: React.ChangeEvent) => { clearTimeout(timerRef.current); diff --git a/docs/data/joy/components/input/InputSlotProps.tsx b/docs/data/joy/components/input/InputSlotProps.tsx index 76b7e2c8a5354c..29b0bc75805783 100644 --- a/docs/data/joy/components/input/InputSlotProps.tsx +++ b/docs/data/joy/components/input/InputSlotProps.tsx @@ -3,7 +3,7 @@ import Input from '@mui/joy/Input'; import Stack from '@mui/joy/Stack'; export default function InputSlotProps() { - const inputRef = React.useRef(null); + const inputRef = React.useRef(null); return ( (); const [left, setLeft] = React.useState(); - const timer = React.useRef | undefined>(undefined); + const timer = React.useRef>(undefined); const countdown = () => { timer.current = setInterval(() => { setLeft((prev) => (prev === undefined ? prev : Math.max(0, prev - 100))); diff --git a/docs/data/joy/components/textarea/TextareaRef.tsx b/docs/data/joy/components/textarea/TextareaRef.tsx index 31ab292a899a18..e5b08f18970e1d 100644 --- a/docs/data/joy/components/textarea/TextareaRef.tsx +++ b/docs/data/joy/components/textarea/TextareaRef.tsx @@ -4,7 +4,7 @@ import Textarea from '@mui/joy/Textarea'; import Stack from '@mui/joy/Stack'; export default function TextareaRef() { - const textareaRef = React.useRef(null); + const textareaRef = React.useRef(null); const handleTextareaFocus = () => { textareaRef.current?.focus(); diff --git a/docs/data/material/components/popper/VirtualElementPopper.tsx b/docs/data/material/components/popper/VirtualElementPopper.tsx index 2c0eae47e0d5d0..634a940c4445aa 100644 --- a/docs/data/material/components/popper/VirtualElementPopper.tsx +++ b/docs/data/material/components/popper/VirtualElementPopper.tsx @@ -8,7 +8,7 @@ export default function VirtualElementPopper() { const [open, setOpen] = React.useState(false); const [anchorEl, setAnchorEl] = React.useState(null); - const previousAnchorElPosition = React.useRef(undefined); + const previousAnchorElPosition = React.useRef(undefined); React.useEffect(() => { if (anchorEl) { diff --git a/docs/data/material/components/progress/CircularIntegration.tsx b/docs/data/material/components/progress/CircularIntegration.tsx index c0e3761c48905b..5f6020368f8e3c 100644 --- a/docs/data/material/components/progress/CircularIntegration.tsx +++ b/docs/data/material/components/progress/CircularIntegration.tsx @@ -10,7 +10,7 @@ import SaveIcon from '@mui/icons-material/Save'; export default function CircularIntegration() { const [loading, setLoading] = React.useState(false); const [success, setSuccess] = React.useState(false); - const timer = React.useRef | undefined>(undefined); + const timer = React.useRef>(undefined); const buttonSx = { ...(success && { diff --git a/docs/data/material/components/progress/DelayingAppearance.tsx b/docs/data/material/components/progress/DelayingAppearance.tsx index 024769f55ca7a0..986578b2e4e1c1 100644 --- a/docs/data/material/components/progress/DelayingAppearance.tsx +++ b/docs/data/material/components/progress/DelayingAppearance.tsx @@ -8,9 +8,7 @@ import Typography from '@mui/material/Typography'; export default function DelayingAppearance() { const [loading, setLoading] = React.useState(false); const [query, setQuery] = React.useState('idle'); - const timerRef = React.useRef | undefined>( - undefined, - ); + const timerRef = React.useRef>(undefined); React.useEffect( () => () => { diff --git a/docs/pages/blog.tsx b/docs/pages/blog.tsx index e2d504dcfae573..1e65953edadc30 100644 --- a/docs/pages/blog.tsx +++ b/docs/pages/blog.tsx @@ -169,7 +169,7 @@ const PAGE_SIZE = 7; export default function Blog(props: InferGetStaticPropsType) { const router = useRouter(); - const postListRef = React.useRef(null); + const postListRef = React.useRef(null); const [page, setPage] = React.useState(0); const [selectedTags, setSelectedTags] = React.useState>({}); const { allBlogPosts, tagInfo: rawTagInfo } = props; diff --git a/docs/pages/experiments/joy/style-guide.tsx b/docs/pages/experiments/joy/style-guide.tsx index 51c136036411c7..0f6603a8abeff6 100644 --- a/docs/pages/experiments/joy/style-guide.tsx +++ b/docs/pages/experiments/joy/style-guide.tsx @@ -62,7 +62,7 @@ function ColorSchemePicker() { function ColorToken({ name, value }: { name: string; value: string }) { const [color, setColor] = React.useState(''); - const ref = React.useRef(null); + const ref = React.useRef(null); React.useEffect(() => { if (ref.current && typeof window !== 'undefined') { const style = window.getComputedStyle(ref.current); diff --git a/docs/src/components/header/HeaderNavBar.tsx b/docs/src/components/header/HeaderNavBar.tsx index 778f20e6f207f9..16ba5aa2759a7c 100644 --- a/docs/src/components/header/HeaderNavBar.tsx +++ b/docs/src/components/header/HeaderNavBar.tsx @@ -137,8 +137,8 @@ const ProductSubMenu = React.forwardRef( export default function HeaderNavBar() { const [subMenuOpen, setSubMenuOpen] = React.useState(null); const [subMenuIndex, setSubMenuIndex] = React.useState(null); - const navRef = React.useRef(null); - const productSelectorRef = React.useRef(null); + const navRef = React.useRef(null); + const productSelectorRef = React.useRef(null); const productsMenuRef = React.useRef(null); const docsMenuRef = React.useRef(null); diff --git a/docs/src/components/pricing/PricingTable.tsx b/docs/src/components/pricing/PricingTable.tsx index 5afc2add270c1b..c7789a0572181c 100644 --- a/docs/src/components/pricing/PricingTable.tsx +++ b/docs/src/components/pricing/PricingTable.tsx @@ -1284,7 +1284,7 @@ export default function PricingTable({ } }, [router.query]); - const tableRef = React.useRef(null); + const tableRef = React.useRef(null); const gridSx = { display: 'grid', gridTemplateColumns: `minmax(160px, 1fr) repeat(${plans.length}, minmax(${ diff --git a/docs/src/components/productBaseUI/BaseUICustomization.tsx b/docs/src/components/productBaseUI/BaseUICustomization.tsx index 322d57b7f68f80..b1263233e99c6f 100644 --- a/docs/src/components/productBaseUI/BaseUICustomization.tsx +++ b/docs/src/components/productBaseUI/BaseUICustomization.tsx @@ -219,7 +219,7 @@ function SwitchFromHook(props: UseSwitchParameters) { export default function BaseUICustomization() { const [index, setIndex] = React.useState(0); - const infoRef = React.useRef(null); + const infoRef = React.useRef(null); function getSelectedProps(i: number) { return { selected: index === i, diff --git a/docs/src/components/productMaterial/MaterialStyling.tsx b/docs/src/components/productMaterial/MaterialStyling.tsx index 1e3097b9b34afd..2cf91516e1da3a 100644 --- a/docs/src/components/productMaterial/MaterialStyling.tsx +++ b/docs/src/components/productMaterial/MaterialStyling.tsx @@ -66,9 +66,9 @@ const scrollTo = [27, 10, 4]; export default function MaterialStyling() { const [index, setIndex] = React.useState(0); - const objectRef = React.useRef(null); + const objectRef = React.useRef(null); const { dragging, getDragHandlers } = useResizeHandle(objectRef, { minWidth: '253px' }); - const infoRef = React.useRef(null); + const infoRef = React.useRef(null); const getSelectedProps = (i: number) => ({ selected: index === i, diff --git a/docs/src/modules/components/JoyThemeBuilder.tsx b/docs/src/modules/components/JoyThemeBuilder.tsx index 67753753411c4b..a4fc588f4cc30e 100644 --- a/docs/src/modules/components/JoyThemeBuilder.tsx +++ b/docs/src/modules/components/JoyThemeBuilder.tsx @@ -714,8 +714,8 @@ function PaletteImport({ function ColorTokenCreator({ onChange }: { onChange: (name: string, value: string) => void }) { const [open, setOpen] = React.useState(false); - const nameRef = React.useRef(null); - const colorRef = React.useRef(null); + const nameRef = React.useRef(null); + const colorRef = React.useRef(null); const [name, setName] = React.useState(''); const [color, setColor] = React.useState(''); if (!open) { @@ -876,7 +876,7 @@ function GlobalVariantTokenCreator({ const [open, setOpen] = React.useState(false); const [name, setName] = React.useState(''); const [color, setColor] = React.useState(''); - const inputRef = React.useRef(null); + const inputRef = React.useRef(null); if (!open) { return (