#how to make two-way data transfer through components?

19 messages · Page 1 of 1 (latest)

ionic ether
#

I need to pass a value from a child component to a parent component and back again and idk how to make it

upper wasp
upper wasp
#

Why?

ionic ether
#

I need to send it through props

#

without context

#

It's possible in React, but it's not possible here

ionic ether
#

I'd like at least a crutch variant

rose tinsel
#

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

ionic ether
#

Why can't props be a function?

rose tinsel
#

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

floral basin
#
  const [value, setValue] = createSignal()

return (
   <ChildComponent setValue={setValue} />
)

Then in the ChildComponent you just do:

props.setValue(5)

And it will change in the parent

rose tinsel
#

As I said before, you could send signal setters to the child. That's that.