State Example - combining two states into one

PHOTO EMBED

Wed Jun 29 2022 15:11:21 GMT+0000 (Coordinated Universal Time)

Saved by @amarMohammed

//Was original state
const [x, setX] = useState(0);
const [y, setY] = useState(0);

//Refactorerd state
const [position, setPosition] = useState({ x: 0, y: 0 });
content_copyCOPY

https://blog.bitsrc.io/5-best-practices-for-handling-state-structure-in-react-f011e842076e