solidjs-community/solid-primitives

use `MultiProvider` with arbitrary props and not only `value: T`

Open

#755 opened on Feb 15, 2025

 (1 comment) (1 reaction) (0 assignees)TypeScript (153 forks)auto 404
enhancementhelp wanted

Repository metrics

Stars
 (1,541 stars)
PR merge metrics
 (PR metrics pending)

Description

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

Contributor guide