SolidJSS
SolidJSโ€ข3y agoโ€ข
4 replies
Ladvace

Reactive var in obj

I have a context provider with an object, one of the property is conditional based on a prop you pass, what is the best way to handle the reactive property in this case?

  const query = () =>
    condition ? 1 : 2;

  const context = {
    // ... other properties
    query: query(),  // The reactive variable 'query' should be used within JSX, a tracked                         scope (like createEffect), or inside an event handler function.
  };

  return (
    <Wrapper.Provider value={context}>
      {props.children}
    </Wrapper.Provider>
  );
Was this page helpful?