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.
You can use arrow function to define your changeRoute handler.
This is known as Class field syntax. More on it here in official react docs.
constructor() {
super(props)
}
changeRoute = (parameter) => (event) => {
// business logic for route change.
}
Then you can use this function directly like so:
render() {
return (
<>
1
2
>
)
}
You do not have to worry about the binding.
Arrow functions inherit their parent's this.