Binding value from child component to parent #851
Replies: 5 comments 1 reply
-
In Vue child.value is getter and setter You can try this way. This is just my idea but I haven't encountered any bugs: interface SignalValue<T> {
(): T
value: T
}
const createSignalValue = <T>(initValue: T) => {
const [signal, setSignal] = createSignal(initValue);
const self = () => signal();
return Object.defineProperty(self, 'value', {
get: signal,
set: setSignal
}) as SignalValue<T>
} |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Here's a cheap trick <Child
{...{
get username() {
return something();
},
set username(value) {
setSomething(value);
},
}}
/> then in props.username = 'John Doe'; |
Beta Was this translation helpful? Give feedback.
-
@walmartwarlord |
Beta Was this translation helpful? Give feedback.
-
Provide a full signal tuple as a prop. import { createSignal, Signal } from 'solid-js';
function Parent() {
const [count, setCount] = createSignal(0);
return <Child count={[count, setCount]} />;
}
function Child(props: { count: Signal<number> }) {
const [count, setCount] = props.count;
return <></>;
} |
Beta Was this translation helpful? Give feedback.
-
Hi, in svelte we can bind a child value to a parent like this:
Child component
Parent component
Every time username updates, the
something
from parent component will also have its value.I understand that in order to do this in solid we set the state in parent and pass it together with its' setter in the child component.
Just want to know if there's another way of doing this...
Another example is this for Vue
Beta Was this translation helpful? Give feedback.
All reactions