Skip to content

Context-API support #161

Open
Open
@Hunter-Gu

Description

@Hunter-Gu

Discussed in #152

Originally posted by yahia-berashish October 25, 2023
Hello, I tried to migrate React Context API to VanJS. The key steps:

  • create a class name and unique id for context provider, and store provide value
  • find the ancestor with class name by element.closest() when use context
  • get the unique id from dom element id, then get the provide value from store

Current drawback: it will always get the default context when component render, because the framework hasn't bind the reactive state and dom, and it's a little tricky to find the ancestor context provider.

Try it on sandbox: https://codesandbox.io/p/sandbox/vanjs-context-provider-poc-qsgdr8?file=%2Fsrc%2Fmain.ts%3A5%2C1

I want to know if there any recommendations about this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions