samedi 7 mai 2022

React - What am i doing wrong about checkbox and axios?

It seems like i've a big misunderstanding of checkboxes/toggle. What I'm trying to do is, to change status of checkbox/toggle from true to false and otherway around.

The axios request working fine. I can change any text back and force. But when ever it comes to toggle a value I'm failing. It always ends in: I can set the value from false to true. But never from true to false.

My state shows correct value so when i click the toggle it shows in console: true, false, true, false...

But when I try to send it to the server and print console.log(req.body.isClosed); in my backend only in the case from false to true it will print a "true". From false to true it's a "undefined"

So ya here i am i tried since 5h to fix it. Used pure checkboxes, react-multi-switch-toggle and now mui switch... Hope someone can help me

const [isClosed, setIsClosed] = React.useState(false);

const handleIsClosed = (event) => {
 setIsClosed(event.target.checked);
};
<Switch
checked={isClosed}
onChange={handleIsClosed}
inputProps=aria-label
/>



Aucun commentaire:

Enregistrer un commentaire