Skip to content

Commit a095200

Browse files
use useState instead of useRef
1 parent 377a683 commit a095200

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

apps/site/components/Downloads/Release/PlatformDropdown.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import Select from '@node-core/ui-components/Common/Select';
44
import { useTranslations } from 'next-intl';
5-
import { useEffect, use, useMemo, useRef } from 'react';
5+
import { useEffect, use, useMemo, useState } from 'react';
66

77
import useClientContext from '#site/hooks/useClientContext';
88
import { ReleaseContext } from '#site/providers/releaseProvider';
@@ -27,12 +27,13 @@ const PlatformDropdown: FC = () => {
2727
// Track whether the user has manually selected a platform via the dropdown.
2828
// When true the OS/version effect will respect their choice instead of
2929
// resetting to the auto-detected value.
30-
const userSelectedPlatformRef = useRef(false);
30+
const [userHasSelectedPlatform, setUserHasSelectedPlatform] = useState(false);
3131

3232
useEffect(
3333
() => {
3434
if (currentPlatform) {
35-
userSelectedPlatformRef.current = false;
35+
// eslint-disable-next-line @eslint-react/set-state-in-effect
36+
setUserHasSelectedPlatform(false);
3637
release.setPlatform(currentPlatform);
3738
}
3839
},
@@ -62,7 +63,7 @@ const PlatformDropdown: FC = () => {
6263
// If the user has not manually selected a platform and there is a currently
6364
// auto-detected one then use it otherwise fallback to the current release platform
6465
const basePlatform =
65-
!userSelectedPlatformRef.current && currentPlatform
66+
!userHasSelectedPlatform && currentPlatform
6667
? currentPlatform
6768
: release.platform;
6869

@@ -82,7 +83,7 @@ const PlatformDropdown: FC = () => {
8283
placeholder={t('layouts.download.dropdown.unknown')}
8384
ariaLabel={t('layouts.download.dropdown.platform')}
8485
onChange={platform => {
85-
userSelectedPlatformRef.current = true;
86+
setUserHasSelectedPlatform(true);
8687
release.setPlatform(platform);
8788
}}
8889
className="min-w-28"

0 commit comments

Comments
 (0)