Skip to content

children helper seems to break Context, need help. #574

Answered by ryansolid
grenierdev asked this question in Q&A
Discussion options

You must be logged in to vote

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 o…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@grenierdev
Comment options

Answer selected by grenierdev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants