React: Passing value to prop callback ?
I want to pass a value to my props call back function
Example:
<input onChange={(e) => console.log(e.target.value) />
The input onChange prop exposes the event to our callback.
How do I accomplish this in my own component?
12 Replies
just pass it down
this is not deep at all
@barry where does the event come from?
wdym
from onChange
yes
yes from onChange
somewhere you have a normal jsx component that takes a onChange property
@barry
so <input /> has an onChange prop which takes a callback. How does onChange props give our callback the event as an agrument?
somewhere it just calls the function and provides the event
idk what you mean
Are you asking about how React internally has implemented event handlers? Or how to call a function you got from props with a specific value in general?
I think I got it. I was overthink it 🙂
Trying to create my own drag and drop lib and was trying to figure how to pass the result to a callback in my onDragEnd prop
@barry @Valhalaar appreciate the quick responses 🙂
yh no problem
to be fair i am so confused now and i dont see any correlation between your first question and this code lol
oh wait no i get it lol
you're passing that onDragEnd to a dnd component right, you can probably just extend the types of that component
i was going more in this direction
The onDragEnd is called when a DnD component is dropped. When this component is dropped it will invoke the onDragEnd returning the result in which I can then update the state of my lists.