I am using inline arrow function to change the onClick handlers of some divs in my React component, but I know it is not a good way in terms of performance.
The best way currently is to wrap your event handler in useCallback hook as it will prevent your handler function from being created each time render is called.
import React, { useCallback } from 'react'
const MyComponent = ({ changeRoute }) => {
const eventHandler = useCallback(() => {
changeRoute('page1')
}, [changeRoute])
return (
1
)
}
For more info check - useCallback docs