|
|
|
|
|
by LoganDark
458 days ago
|
|
> I don't think it's even React itself that's the root cause the performance problems, it's using the data store badly (Redux or Mobx or even the new ones like Zustand and Valtio) that either causes components to rerender too often or causes too many components to rerender. Like I said, it's shoddy development practices. I've seen apps that use one of those mutable object libraries (not any of the ones you listed) and just pass the objects everywhere. Whole app re-render on any state update because of how all of the state is nested inside these mutable mega-variables held by the root of the component tree. I try to chip away at the innermost components and create little havens that use immutable state as they should, but it's going to take years to redo the whole app that way, especially since refactoring isn't a priority yet. By the way, a cool trick if a component you're using does not use `React.memo` is to memoize the element, because if React sees the exact same (reference-equal) element as the last render, it will not re-render the corresponding component tree. (Element refers to the return type of JSX expressions.) Obviously, only do this if it actually doesn't need to re-render. |
|