I have an object state inside my react component set up like this:
const [state, setState] = useState({ keyOne: true, keyTwo: 'someKey' })
When I change the state, the component obviously rerenders. But that's the problem. The component is rerendering even if I change the state to the value that it's currently set to. For example, the component still rerenders if I do this:
setState({ keyOne: true, keyTwo: 'someKey' });
I'm guessing this is because I'm passing a new object to setState, and so it will be interpreted as a different state each time even if the content in the object is the same. So I guess my question is:
How can I prevent a component from re-rendering if the new object state has the same content as the original state? Is there a built-in way to do this, or will I have to compare the objects beforehand myself?