'Pulling react comp state from class instance
I've used React with MobX (decorators) and TypeScript for a while, but am only now getting around to using React without any 3rd party state management. I've come across a problem, and I suspect the answer is to go 3rd party, but thought to confirm here just in case vanilla react can handle my use case.
I have an application, made up of many various classes, using threejs. As such, its state is in those class instances - its not tied to any React components since it only needs a canvas. Now that I want to add UI elements with React, I'd like to use the properties of those classes that already exist in memory. I don't want to duplicate those existing class props in React setState, updating them at the same time, just to get those React comps to re-render.
MobX 5 handled this nicely with decorators, allowing me to keep state, logic and components separate. Is there no similar way to achieve what I want in vanilla React? I'm happy to use some state management lib otherwise, just thought to ask here! If that's the case, am open to suggestions for super lightweight libs I could use, thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|