Skip to content

Make setContext return the value that was just set. #7427

@gtm-nayan

Description

@gtm-nayan

Describe the problem

It is a common pattern to put stores into context for reactivity, even the docs recommend it, however there is one mildly annoying thing when you want to use that store within the same component. See the examples below (imports removed for brevity):

This one sparks joy (not possible currently)

<script> const my_store_thing = setContext(key, writable()); </script> Do stuff with {$my_store_thing} in the same component.

This one does not

<script> const my_store_thing = writable(); setContext(key, my_store_thing); // my_store_thing is repeated here. </script> Do stuff with {$my_store_thing} in the same component.

Describe the proposed solution

Make setContext return the value that was passed into it as the second argument. Should be a non breaking change AFAIK unless people are doing weird things with it.

Alternatives considered

Leave things as is.

Importance

would make my life easier

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions