React JS V17.0.0: Cannot assign to read only property ‘color’ of object ‘#

You can not use static variables to change virtual DOM.

use useState to change your color.

https://stackblitz.com/edit/react-qkmqcu?file=src%2FApp.js

Explanation

as I told you, you specified read-only const in DOM and you can not mutate it, whenever you click on the button, you must need to rerender your virtual DOM and for that, you must to assign your color into state and error also tells that you can not assign anything that changeable ( means its read-only )

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top