Home > other >  How can I send data from a child component to a child component without using props?
How can I send data from a child component to a child component without using props?

Time:06-08

Is this possible And how to do this. I worked on a similar thing in vuejs like

this.$emit("send",payload)

and then listen in another component

this.$on("send",(payload) => {
/and do something the in another component
}

How to Do this in ReactJS

CodePudding user response:

you can use a react context https://reactjs.org/docs/context.html or redux https://redux.js.org/

CodePudding user response:

What you want is called event bus in vue.js, but it is an anti-pattern so it was removed from the API in vue 3.

However if you really liked that approach, you can probably achieve it with an external library that implements the event emitter interface.

You can read more about it here with provided example: https://v3-migration.vuejs.org/breaking-changes/events-api.html#event-bus

  • Related