From c2eb03461d348b2a4b2b5d854858595cb740020c Mon Sep 17 00:00:00 2001 From: ZeeshanTamboli Date: Sat, 28 Sep 2024 12:32:55 +0530 Subject: [PATCH] improve code and add comment --- packages/mui-material/src/Rating/Rating.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/mui-material/src/Rating/Rating.js b/packages/mui-material/src/Rating/Rating.js index a90a24e96248bf..0bdc81e0b81c0f 100644 --- a/packages/mui-material/src/Rating/Rating.js +++ b/packages/mui-material/src/Rating/Rating.js @@ -242,7 +242,11 @@ function RatingItem(props) { const isFocused = itemValue <= focus; const isChecked = itemValue === ratingValueRounded; - const id = (name ? `${name}-` : '') + useId(); + // "name" ensures unique IDs across different Rating components in React 17, + // preventing one component from affecting another. React 18's useId already handles this. + // Update to const id = useId(); when React 17 support is dropped. + // More details: https://github.com/mui/material-ui/issues/40997 + const id = `${name}-${useId()}`; const container = (