I have a manager class in my app that is just a regular JS class, it's purely logical with no view. I use an instance of it in several of my components. For one of it's actions I'd like it to change the route in my React based app. I know I can return something to each component and then have the component do the routing, but I'd like to know if there is a way to do it from my non-react class. Is there maybe a way to pass in the history object and push the new route to it?
Thanks for any help.
EDIT: It's more of a theoretical/methodolgy question but for example: Manager class:
class MyManagerClass {
constructor() {
this.data = {...some internal data};
}
doSomething(param) {
if(this.data[param]) {
this.data[param]();
} else {
//here i'd like to change the route in my react app
}
}
}
Component:
import React, {useContext, useEffect, useRef, useState} from "react";
const MyComponent = props => {
const myManagerClass = new MyManagerClass();
useEffect(() => {
myManagerClass.doSomething('param');
}, [props.something]);
return (
<div>Component</div>
)
}