Hello,

Hello,
Coming from a different B2B framework, I was looking for something to replace it due to its many limitations. Then I came across Refine, and it seems like it might be what I need.
Currently, I am reading the source code to understand exactly what it does and how it differs from the tool I am currently using. I have a few questions—not about how to do things, but about why certain things are done the way they are.
I noticed that there are lots of useMemo calls for checking simple conditions. For example, in core/router/use-parse:

const useParse = React.useMemo(
() =>
routerContext?.parse ??
(() =>
(() => {
return {};
}) as ParseFunction),
[routerContext?.parse],
);

Why? This is a simple condition—nothing expensive there. If the goal was to keep the reference of the empty function, why not just move it outside of the component?
Another example is in useResourceParams variables: defaultId and formAction
These are not expensive either.

And also this line:

React.useMemo(() => setId(defaultId), [defaultId]);

I know that in some cases we prefer setting a state during the render process, but why use useMemo here?
Wouldn't a simple condition like if (id !== defaultId) setId(defaultId) suffice?
Is there something going on behind the scenes in a Refine app that requires useMemo to be used this often?

From the official documentation of React "You should only rely on useMemo as a performance optimization."
Was this page helpful?