The most common use of React Refs is to store a DOM element. However, the React documentation suggests that refs can be used to store any immutable value, so I was wondering if anyone has been able to implement an actual instance of a class and assigned it to a ref. E.g.:
// Example class
class MyBlueCar {
constructor(options) {
}
...
}
// React component
import { MyBlueCar } from "./mybluecar.js";
function StartCar() {
const startEngineRef = useRef();
useEffect(() => {
const myBlueCar = new MyBlueCar();
startEngineRef.startEngine = myBlueCar
}, []);
}
However I get a startEngineRef is not extensible error.