For the past few days, I have been struggling with creating a hook that returns a component because I really needed a way to link a hook and a component without using global state or context.
What I found in the React docs is that defining a component inside another component is considered an anti-pattern because on every render it will not be considered the same component.
My first thought was basically to put it inside useMemo, but while that may help with re-renders, from what I understand the virtual DOM will still treat it as a different type.
I noticed that useForm has code like this inside a useMemo:
extendedApi.Field = function APIField(props) {
return <Field {...props} form={formApi} />
}```
So I am wondering if anyone has knowledge, documentation links, or references to React sources where I can learn exactly why and how defining a component inside another component is considered an anti-pattern. I would really, really appreciate it because I’m going crazy trying to find a good answer and haven’t had any luck so far.