I am struggling to understand Redux or work with the Context API, so I built this simple class:
import React from "react";
export default class X extends React.Component {
constructor() {
super();
SM["set" + this.constructor.name] = function (obj) {
this.setState(obj);
}.bind(this);
}
}
So if I have a component (e.g. ) whose state needs to be set by other components, it will extend class X and store its setState function in a global object called SM (state manager). So using SM.setCar({/state object/}) will call the this.setState of the component Car.
There's much less headache for me compared to Redux or Context API.
The question is: is it a bad practice? Am I going to have fewer opportunities if employers see this in my code?
If yes, why is it a bad practice?