How do I save/restore the state of an instance of OrbitControls

I am trying to save the state of the camera/orbital-controls for my app. Here are my methods on a subclass of OrbitControls:

// save state
getState() {
    return this.camera.toJSON();
}

// restore state
setState(json) {
	const jsonLoader = new THREE.ObjectLoader();
	this.camera = jsonLoader.parse(json);
	this.update();
}

I am able to restore the camera but the orbit-controls stops working. I loose all interactive control.

Um, OrbitControls does not have a camera property. Can you try it with object instead?.

Yah, I configure the class with a param called camera.

It turns out just clobbering the current object and call update() doesn’t actually work. I fixed the issue by simply updating the pre-existing object with the params - fov, aspect, etc. - I saved in the session state.