solidjs-community / solidjs-community/solid-primitives

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

Open
#755 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
TypeScript
Stars
1.6k
Forks
162
Avg merge
19h 40m
Merged PRs (30d)
8

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the MultiProvider and createContextProvider entry points and their TypeScript prop definitions. Check how MultiProvider passes each context's current value, then verify that contexts created with arbitrary props such as { initial: 1 } can be supplied without wrapping them in { value: ... }.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.