Skip to content

use MultiProvider with arbitrary props and not only value: T #755

Description

@FabianHummel

Describe The Problem To Be Solved

The Context primitive adds functionality to easily create context providers through createContextProvider. Given the example code on the website, ...

const [CounterProvider, useCounter] = createContextProvider((props: { initial: number }) => {
  const [count, setCount] = createSignal(props.initial);
  const increment = () => setCount(count() + 1);
  return { count, increment };
});

// Provide the context
<CounterProvider initial={1}>
  <App />
</CounterProvider>;

... the following code does not work when paired with the MultiProvider as it only accepts a single argument value:

<MultiProvider
  values={[
    [CounterProvider, { initial: 1 }] // not working, as this is passed to the single `value` field.
  ]}
>
  <App />
</MultiProvider>;

Suggest A Solution

It would be nice if the individual contexts of MultiProvider accepted the same props as returned from createContextProvider so they seamlessly work together. A workaround would be to wrap the context props with { value: ContextProps }, but this destroys usability and requires refactoring the entire codebase

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions