3 ms·
But it's not really OO, it's some ugly mix with rules: * don't put side-effect initialization code into the constructor * use state to render your components *
by posix86 5y ago
But it's not really OO, it's some ugly mix with rules:
* don't put side-effect initialization code into the constructor
* use state to render your components
* don't set state directly, use setState, _unless_ in the constructor
* if you want to use stores, declare a static field
You don't inherit classes, as there are many special methods, and overwriting them would mean calling super - before your method body? After? During?
Class based components only pay off if you have truly large and complex components, and that's an antipattern in react anyway. Hooks are concise, and super clear if you keep it simple (there are also additional rules not enforced by the compiler, like putting all side-effectful code into useEffect, but still).