S
SolidJS2y ago
Tur

How to pass data from child component to parent?

We have props in solid for passing data down to child component. What about the opposite case when I need to pass some data back to the parent component? If I am not mistaken, in Vue.js there is a possibility to emit event from parent to child. How can I do it?
10 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Tur
TurOP2y ago
How? Using props? function ChildComplonent(props) { ... props.newProperty = some value } Is that what you mean?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Jérémy
Jérémy2y ago
SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Tur
TurOP2y ago
I just need to pass to the parent which service I've chosen. See on:click event
Tur
TurOP2y ago
Actually, I don't need to share that data (services) globally. I just want to make to pass that to Parent
thetarnav
thetarnav2y ago
use a callback prop
<Child setSomething={data => {...}} />


props.setSomething(data)
<Child setSomething={data => {...}} />


props.setSomething(data)
you don't "emit" events. you just call a function passed down from parent
thetarnav
thetarnav2y ago
You can also use something like this, if working with event object makes more sense to you: https://github.com/solidjs-community/solid-primitives/tree/main/packages/event-dispatcher#createeventdispatcher
GitHub
solid-primitives/packages/event-dispatcher at main · solidjs-commun...
A library of high-quality primitives that extend SolidJS reactivity. - solid-primitives/packages/event-dispatcher at main · solidjs-community/solid-primitives
Tur
TurOP2y ago
Yeah! It works! Thank you!
Want results from more Discord servers?
Add your server