lundi 20 janvier 2020

ReactJS disabling form if checkbox is checked

I have a checkbox. If the checkbox is checked, the form should close. But it doesn't work for me. I have the following code:

const [IsChacked, setIsChacked] = useState(false);

const onChangeParams = (name, setChackedValue, defaultChecked) => {
    if (name === "foreign_citizen") {
        let value = defaultChecked.target.value;           
        setChackedValue(name, value)
        if (parseInt(value) === 1) {
            setIsChacked(true);
        }
    }
};

And my form like this:

<Form.Check
                                                        onChange={(e => onChangeParams("foreign_citizen", e, setChackedValue))}
                                                        name="foreign_citizen"
                                                        defaultChecked={values.foreign_citizen}
                                                        isInvalid={touched.foreign_citizen && !!errors.foreign_citizen}
                                                        type="checkbox"
                                                        label="Наличие паспорта в деле"
                                                    />
  {IsChacked ? (
                                            < > Dos something here
                                            </>
                                        ) : ( <></>)}

If i checked on checkbox it gives like error: TypeError: Cannot read property 'target' of undefined

So where i have wrong? I don't undersanding...




Aucun commentaire:

Enregistrer un commentaire