#Context between Siblings Components
8 messages · Page 1 of 1 (latest)
just have a component C that wrap both ?
I would like on hover to change the price on another component
iT'S more what i want to do
Do i use Context ?
// GrandParent.tsx
import { $, component$, type QRL, useStore } from "@builder.io/qwik";
export const grandParent = component$(() => {
const dataStore = useStore({ message: "" });
const handleDataFromChild = $((data: string) => {
dataStore.message = data;
});
return (
<div>
<h1>data received from child : {dataStore.message}</h1>
<Parent onReceiveData={handleDataFromChild} />
</div>
);
});
interface ParentProps {
onReceiveData: QRL<(data: string) => void>;
}
export const Parent = component$(({ onReceiveData }: ParentProps) => {
return <Child sendDataToGrandParent={onReceiveData} />;
});
interface ChildProps {
sendDataToGrandParent: QRL<(data: string) => void>;
}
export const Child = component$(({ sendDataToGrandParent }: ChildProps) => {
const sendData = $(() => {
sendDataToGrandParent("i child (Qwik)!");
});
return (
<button type="button" onClick$={sendData}>
Send
</button>
);
});