Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Content]: Does not provide how to use a signal a the value of the context using TypeScript #810

Open
jmaister opened this issue Jul 8, 2024 · 1 comment
Labels
solid Related to core Solid

Comments

@jmaister
Copy link

jmaister commented Jul 8, 2024

📚 Subject area/topic

/concepts/context.mdx

📋 Page(s) affected (or suggested, for new content)

Updating context values

📋 Description of content that is out-of-date or incorrect

I am trying to create context and sending a signal as value. Using the example from "Updating context values"
In the example, what should be the type used to create the context?
It can't be number as it is retunring an array with the value and functions.

🖥️ Reproduction in StackBlitz (if reporting incorrect content or code samples)

No response

@jmaister
Copy link
Author

jmaister commented Jul 8, 2024

I found a way of sending the signal as a value of the context, and keeping the right types.

The key is to use "function that returns the type of my value": () => LoggedUser as type.

export interface LoggedUser {
    isLoggedIn: boolean;
    isLoading: boolean;
    user: User | null;
}

const defaultLoggedUser: LoggedUser = {
    isLoggedIn: false,
    isLoading: true,
    user: null,
};

export const LoggedUserContext = createContext<[() => LoggedUser]>([() => defaultLoggedUser]);

@LadyBluenotes LadyBluenotes removed their assignment Sep 25, 2024
@LadyBluenotes LadyBluenotes added solid Related to core Solid and removed pending review Awaiting review by team members. improve documentation labels Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solid Related to core Solid
Projects
None yet
Development

No branches or pull requests

2 participants