how to make two-way data transfer through components?

I need to pass a value from a child component to a parent component and back again and idk how to make it
10 Replies
Jasmin
Jasmin10mo ago
sounds like a good use case for contexts. https://docs.solidjs.com/concepts/context
Дикий
ДикийOP10mo ago
doesn't fit
Jasmin
Jasmin10mo ago
Why?
Дикий
ДикийOP10mo ago
I need to send it through props without context It's possible in React, but it's not possible here doesn't fit the project structure I'd like at least a crutch variant
high1
high110mo ago
How do you mean through props? Props are sent from the parent to the child component But those props could be signals, i.e. you could send signal setters to the child If you don't want context - or stores
Дикий
ДикийOP10mo ago
Why can't props be a function?
high1
high110mo ago
they can but the easiest way to have a change in child component visible in parent is to forward something that is already reactive and that's either a setter, or a shared store, context, even a function wrapper around something that's reactive
Grahf
Grahf10mo ago
const [value, setValue] = createSignal()

return (
<ChildComponent setValue={setValue} />
)
const [value, setValue] = createSignal()

return (
<ChildComponent setValue={setValue} />
)
Then in the ChildComponent you just do:
props.setValue(5)
props.setValue(5)
And it will change in the parent
high1
high110mo ago
As I said before, you could send signal setters to the child. That's that.
Дикий
ДикийOP10mo ago
it's working thanks
Want results from more Discord servers?
Add your server