Fixed reference error

This commit is contained in:
Alejandro Celaya
2022-04-03 10:10:10 +02:00
parent bd549c8642
commit 965e69c525
6 changed files with 44 additions and 62 deletions

View File

@@ -1,7 +1,7 @@
import { ChangeEvent, FC, useRef } from 'react';
import { ChangeEvent, FC } from 'react';
import classNames from 'classnames';
import { v4 as uuid } from 'uuid';
import { identity } from 'ramda';
import { useDomId } from './helpers/hooks';
export interface BooleanControlProps {
checked?: boolean;
@@ -17,7 +17,7 @@ interface BooleanControlWithTypeProps extends BooleanControlProps {
const BooleanControl: FC<BooleanControlWithTypeProps> = (
{ checked = false, onChange = identity, className, children, type, inline = false },
) => {
const { current: id } = useRef(uuid());
const id = useDomId();
const onChecked = (e: ChangeEvent<HTMLInputElement>) => onChange(e.target.checked, e);
const typeClasses = {
'form-switch': type === 'switch',

View File

@@ -2,6 +2,7 @@ import { useState, useRef, EffectCallback, DependencyList, useEffect } from 'rea
import { useSwipeable as useReactSwipeable } from 'react-swipeable';
import { useNavigate } from 'react-router-dom';
import { parseQuery, stringifyQuery } from './query';
import { v4 as uuid } from 'uuid';
const DEFAULT_DELAY = 2000;
@@ -82,3 +83,8 @@ export const useGoBack = () => {
return () => navigate(-1);
};
export const useDomId = (): string => {
const { current: id } = useRef(`dom-${uuid()}`);
return id;
};