In components, I\'ve seen different way of doing callbacks. What is the difference between:
{doSomething(data)} }>
{doSomething(data)} }>
Is calling a new anonymous function onPress
, which will run doSomething
.
Is calling a reference to a named function, that you have already defined in your class. The binding to this is required only when you are working with class function (I mean, non ES6 arrow function).
const doSomething = () => { ... }
Would not require a .bind(this)
, since arrow functions bind on lexical scope.
You should definately read over What is the best and most efficient way to bind callbacks in ReactJS? In the constructor or in the render method or as a property initializer?