Open
Description
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
Labels
No labels