'React checkbox data from mongodb

I try check if checkbox is checked in mongodb or not So for isClosed my value in db is true And its working so far my checkbox is checked bcs its true in db. But i cant toggle it. It will stay checked for ever how can i make it toggle again?

                        <label className='flex justify-between'>
                          <div className='pl-8'>Holidaymode:</div>
                          <input
                            type='checkbox'
                            checked={
                              settings[0]?.isClosed === true ? 'checked' : null
                            }
                            onChange={handleChange}
                            className='mt-2 mr-8'
                          />
                        </label>


Solution 1:[1]

If the value is stored in a database, you have to modify the value in the database, this value will be automatically repeated on the checkbox

So each time the onChange method is called, make a request to the server to change the state of the variable

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 horhorou