mercredi 16 novembre 2022

Passing values from a constant to the e.target.value

I am working on building out a radio component and when checked I want the values from the radio button to pass when set onBlur. I am trying to pass a function to the onBlur but I am not seeing the values on my Form Submit action.

const [isChecked, setIsChecked] = React.useState<boolean>(defaultValue);
    const onValue = React.useMemo(() => {
        if (!isChecked) return [`${label}, ${description}`];
    }, [onChange]);
    const checkedValue = React.useCallback(
        (e: React.ChangeEvent<HTMLInputElement>) =>
            onChange?.(onValue, e.target.value),
        [onChange]
    );

    
    return (
        <div className="space-y-5">
            <div className="relative flex items-start">
                <div key={id} className="flex h-5 items-center">
                    <input
                        id={`${label}-id`}
                        name={label}
                        type="radio"
                        className="h-4 w-4 border-gray-300 text-indigo-600 focus:ring-indigo-500"
                        
                        onBlur={checkedValue)}
                        onChange={() => setIsChecked(!isChecked)}
                    />
                </div>
                <div className="ml-3 text-sm">
                    <label
                        htmlFor={`${label}-id`}
                        className="block font-medium text-gray-700"
                    >
                        {label}
                    </label>
                    <p id={`${label}-description`} className="text-gray-500">
                        {description}
                    </p>
                </div>
            </div>
        </div>
    );
};



Aucun commentaire:

Enregistrer un commentaire