I am currently upgrading my codebase to react 19 and using the compiler. Traditionally in react inline arrow functions in the jsx were considered bad practice for performance reasons, however I am trying to find confirmation on whether the react compiler will handle this use case now and I can safely use inline functions.
e.g previously I may have done something like this:
const testFunction = useCallback(() => {
doSomething(id)
}, [id])
<Button onClick={testFunction} />
but can this now be simplified to:
<Button onClick={() => doSomething(id)} />
without affecting performance.
Does anyone know if the compiler will handle inline arrow function now? I would be especially interested to know from anyone that may have worked on the compiler itself to be able to confirm.
I have done some searching through google and reading the docs but haven't found explicit confirmation on this.
useCallbackversion would not be faster unlessButtonis memoized and the props didn't change, otherwise it's marginally slower and more memory inefficient. And memoizing a Button probably wouldn't be worth it vs useCallback + memo retaining a copy of props and doing a comparisonuseCallbackhook was always about providing a stable callback prop value and not a performance enhancement. I think "considered a bad practice" was just mis-intentioned premature optimization.