import { component$, useStore, QRL } from "@builder.io/qwik";
export const App = component$(() => {
const store1 = useStore({ count: 0 });
const store2 = useStore({ count: 0 });
return (
<button onClick$={() => store1.count++}>
// PROBLEM: Root should always re-render
// because we don't know that `store` is constant
<CountStore store={Math.random() > 0.5 ? store1 : store2} />
<CountStore store{store1} />
<PassThrough value$={() => store1.count + 1} />
</button>
);
});
export const PassThrough = component$(
(props: { valueQrl?: QRL<() => number> }) => {
return <CountRef valueQrl={props.valueQrl} />;
}
);
export const CountStore = component$((props: { store: { count: number } }) => {
useTrack(props, 'store');
return <span>{props.store.count}</span>;
});
export const CountRef = component$(
(props: { store?: { count: number }; valueQrl?: QRL<() => number> }) => {
return <span>{props.valueQrl?.invoke()}</span>;
}
);
Options:
const
by defaultvar
through marker<ChildComponent title={mutable(expr)}/>