I want to point out something. In your first example, if you don't memoize, the input component's addEventListener and removeEventListener will be called in every render. For a native input this may not be a big problem but if it is not an input but a custom blackboxed component, it is almost always better to memoize. Because you will not know the cost of not memoizing. Generally you should memoize things you pass as props to other components.
Yes, I agree, but it would be only helpful if the blackboxed component is a memoized component or a component that relies on the function being referentially equal on every re-render of the parent component (like it uses the function in the dependency array of a useEffect).
In any other case, it would be completely useless to memoize the function because the blackboxed component would re-render anyways if the parent component re-renders.
Also, I think the author of the blackboxed component should inform the consumer if it relies on the function being referentially equal.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I want to point out something. In your first example, if you don't memoize, the input component's
addEventListener
andremoveEventListener
will be called in every render. For a native input this may not be a big problem but if it is not aninput
but a custom blackboxed component, it is almost always better to memoize. Because you will not know the cost of not memoizing. Generally you should memoize things you pass as props to other components.Yes, I agree, but it would be only helpful if the blackboxed component is a memoized component or a component that relies on the function being referentially equal on every re-render of the parent component (like it uses the function in the dependency array of a
useEffect
).In any other case, it would be completely useless to memoize the function because the blackboxed component would re-render anyways if the parent component re-renders.
Also, I think the author of the blackboxed component should inform the consumer if it relies on the function being referentially equal.