TypeError: Assignment to constant variable. React.js Hook [closed]

The error is self descriptive I guess. You need to use the setter instead of assigning a value directly to your state object.

Avoid this:

toggle = !toggle

Replace your onClick to not to re-assign:

onClick={() => setToggle(!toggle)}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top