ㄹㅇ 리액트 진짜 처음 써봐서 그런데

const [dataStore, setDataStore] = useState(new TreeDataStore())

이렇게 초기화하고

setDataStore((prevDataStore) => {
prevDataStore.setData(jsonObj);
return prevDataStore;
});

이렇게 쓰고싶은데 이러면 setter을 실행했음에도 컴포넌트 재렌더링이 안되는게 문제인데

useState에 객체 넣고 쓰면 안되나?

TreeDataStore은 데이터 넣고 undo랑 redo 할 수 있게 이런식으로 구현해본거라
caretaker이 이전의 데이터 기록을 가지고 있게하려면 하나의 객체를 유지한 상태로 setData()를 통해 데이터를 설정해줄 필요가 있는데 ㅇㅇ..

class TreeDataStore {
constructor() {
this.data = {};
this.caretaker = new Caretaker();
}


setData(newData) {
this.caretaker.addMemento(new Memento(this.data));
this.data = newData;
}

undo() {
const previousData = this.caretaker.getPreviousMemento().getData();
this.data = previousData;
}

redo() {
const nextData = this.caretaker.getNextMemento().getData();
this.data = nextData;
}
} // 생략