javascript - when communicate between component in react or vuejs, what's the different between using callback and event -
as title say,i confused communicate between parent-child components in react or vuejs.
there 2 different way communicate between components.
- first,we can pass method prop child component, child can communicate parent component through method;
- second,we can dispatch event in child component , parent can listen event something.
my confusion difference.when should use method , when should use event?
a prop not method, data item representing piece of program state. although possible (using .sync
) child modify prop , have change propagate parent , common child receive prop parent , reflect updates from parent.
an event way of saying happened, user clicked button. component dispatches event parent (or whatever other component) can make changes state (which propagate down via props).
the usual rule props go down children, events go parents.
Comments
Post a Comment