Open luislpv22 opened 3 years ago
I've tried before with this:
import { createContext } from '@jsx-lite/core';
export const MenuContext = createContext({ foo: 'bar' });
export default function MyComponent(props) {
return (
<MenuContext.Provider>
{props.children}
</MenuContext.Provider>
)
}
But it outputs that:
JSON
{
"@type": "@jsx-lite/component",
"imports": [],
"meta": {},
"state": {},
"children": [
{
"@type": "@jsx-lite/node",
"meta": {},
"properties": {},
"bindings": {},
"children": [
{
"@type": "@jsx-lite/node",
"name": "div",
"meta": {},
"properties": {
"_text": "\n "
},
"bindings": {},
"children": []
},
{
"@type": "@jsx-lite/node",
"name": "div",
"meta": {},
"properties": {},
"bindings": {
"_text": "props.children"
},
"children": []
},
{
"@type": "@jsx-lite/node",
"name": "div",
"meta": {},
"properties": {
"_text": "\n "
},
"bindings": {},
"children": []
}
]
}
],
"hooks": {},
"name": "MyComponent"
}
REACT
export default function MyComponent(props) {
return (
<>
<undefined>{props.children}</undefined>
</>
);
}
@luislpv22 you're correct context is not yet implemented but on the todo list! will follow up here when we have updates on that
Any progress on this please? I was looking into translating some React into JSX-Lite, but seems useContext is all the rage these days ;)
definitely still on the todo list - trying to carve off time soon to knock out this and a few other things!
actively working on this over here https://github.com/BuilderIO/jsx-lite/pull/113
useContext seems implemented but not documented, isn't it?
yeah not documented because there were questions on what the angular/webcomponent version looks like
to create the context for angular. I still need to work on here. https://github.com/BuilderIO/mitosis/issues/330 but to consume context works correctly. For what you're doing there might be some questions on how it would work with Angular and other frameworks if everything was in Mitosis
Idea for webcomponent: emit code that stores context on the DOM, and walks up the DOM to retrieve it.
For webcomponent thats exactly how i wrote it and the context can be a Map instance
Because to use a state management library that is agnostic to the framework is too much? Examples:
@CKGrafico There is absolutely nothing preventing someone from using a (framework-agnostic) library with their Mitosis components! That should work just fine 😄
Sorry for the late response @samijaber I'm thinking into combine your useState with zustand seems the best option. I was also thinking into totally avoid your usestate to be sure that all the frameworks have state, for example using https://jotai.org/ but I hope is not going to be necessary.
Thanks for your work!
:(
BTW, is still imposible to use useState in angular right?
@CKGrafico That is a separate bug that we should look into
yeah not documented because there were questions on what the webcomponent version looks like
@PatrickJS - We did a big audit of web component / dom context implementations. There are a lot of different implementations, but all of them are subtly different, have different support for disconnect/connect due to moving dom nodes around, different event namespaces, and different support for arbitrary nesting.
I have tried to help move all of these dom context implementation towards a simple, centralized specification and standard. I haven't been as pro-active lately in trying to track down and centralize the approach.
See prior art and related projects in the readme: https://github.com/saasquatch/dom-context
I think it makes sense to allow for anyone to toggle the DOM context standard you're proposing or at least allow for a way to use it. the problem with web components is that it's not a framework and you have to add everything a framework adds. Web components doesn't have any standards for most framework things so everyone has to make up their own.
The other thing about context is that you want types so we want to support strings but ultimately we want to support direct references to get the type info
I need to redo web components rendering and context which may effect how best solution for context. A lot of the web component context workarounds in the current implementation is due to having to work with the DOM directly rather than creating a copy then creating the view-ready version to insert or diff. I think we can go back to the simple version of rendering and context we have before in web components if we create copies rather than working with strings and current view.
Also it looks like there is a community proposal Context Community Protocol by the W3C's Web Components Community Group developed by the Lit team since we published dom-context
.
I've realised that createContext and useContext features aren't implemented yet. Is there an ETC for these features?
Btw, this package is awesome, looks very promising to me.
Thanks!