DEV Community

Discussion on: Understand One-way Data Binding in React the easy way!

Collapse
salarc123 profile image
SalarC123 • Edited

I’m curious as to why you passed a callback to the child instead of just directly passing the setText function

Collapse
parnikagupta profile image
Parnika-Gupta Author

Hey there is no particular reason I did that. Is there a reason why we should or shouldn't be using arrow functions when we can directly pass the setText function? I would love to learn more about the depth of it.

Collapse
permanar profile image
Richie Permana

IMHO, its just matter of simplicity and consistency.

<Child setText={ setText }>
// is the same as
<Child setText={(text) => { setText(text) }}>

// but not as
<Child setText={ setText() }>
//or
<Child setText={(text) => setText(text)}>
Enter fullscreen mode Exit fullscreen mode

CMIIW.

Thread Thread
parnikagupta profile image
Parnika-Gupta Author

I just saw a video on callbacks that made it clear for me.. I will find it again to grab a link and share if anyone needs...But what's the difference between 2nd format and the 4th one that you have shared?

Collapse
salarc123 profile image
SalarC123

I’m not actually sure. I’ve just always done it like this, but I don’t really see any differences between the two methods