children
helper seems to break Context, need help.
#574
-
The following playground should show two identical counters under
How can we check if a component has children while keeping the context chain and not evaluating the children multiple times? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Would this work for your scenario? function MenuItem(props) {
console.log('MenuItem1', props.label);
const [lost, setLost] = createSignal(0);
const hasChildren = "children" in props;
const t = setInterval(() => setLost(d => d + 1), 1000);
onCleanup(() => { console.log('cleanup1'); clearInterval(t); });
return (
<li>
<span>{props.label} <Show when={hasChildren} fallback={<small title="alone">🙍</small>}><small title="has children">👩👦</small></Show></span>
<LostContext.Provider value={lost}>
{props.children}
</LostContext.Provider>
</li>
);
} You are correct using the children helper above the context provider executes all children outside of the context. I believe the |
Beta Was this translation helpful? Give feedback.
Would this work for your scenario?
You are correct using the children helper above the context provider executes all children outside o…