Skip to content

Commit

Permalink
fix: create id with useMemo instead of useState
Browse files Browse the repository at this point in the history
  • Loading branch information
beawar committed Jul 18, 2023
1 parent a8dde94 commit 489d164
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/inputs/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ const RadioComponent = React.forwardRef(function RadioFn<
const radioInputRef = useCombinedRefs<HTMLInputElement>(inputRef);
const labelRef = useRef<HTMLDivElement>(null);
const [isChecked, setIsChecked] = useState(checked ?? defaultChecked ?? false);
const [id] = useState((): string => {
const id = useMemo<string>(() => {
const RadioComponentAlias = RadioComponent as RadioType;
if (RadioComponentAlias._id === undefined) {
RadioComponentAlias._id = 0;
}
const { _id } = RadioComponentAlias;
RadioComponentAlias._id += 1;
return `Radio-${_id}`;
});
}, []);

const uncontrolledMode = useMemo(() => typeof checked === 'undefined', [checked]);

Expand Down

0 comments on commit 489d164

Please sign in to comment.