yelping-magenta
yelping-magenta2mo ago

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."
1 Reply
multiple-amethyst
multiple-amethyst5w ago
Hey @0ktay thank you for taking your time to dive into the source code 🙏 You're right, these patterns looks like unnecessary optimizations and there are definitely some easy gains to replace them. Considering Refine's role as a framework that is used deeply in projects, we always try to avoid falling for re-render loops but this sometimes cause lines like those get overlooked after development. However, we're always open to contributions and feedbacks coming from our users 🚀 We'd love to see your PR about them if you want to contribute 🍀 Thanks again for the review, we'll be including this to our to-do. This kind of detailed feedback helps us make Refine better for everyone.

Did you find this page helpful?