-
Notifications
You must be signed in to change notification settings - Fork 527
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
poc: common JSX components #5952
base: master
Are you sure you want to change the base?
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit e872fb0:
|
const augmentH = (baseH) => (tag, propsWithClassName, children) => { | ||
const { className, ...props } = propsWithClassName; | ||
return baseH(tag, Object.assign(props, { class: className }), [children]); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to map className
to class
and children has to be an array for Vue's h
function (they don't have fragments)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vue 2 and 3 are quite different, we have renderCompat, but I wonder if we should just have separate files for vue 2 and vue 3 once we simplify the rendering?
|
||
const h = augmentH(baseH); | ||
|
||
return createHits({ createElement: h })({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call to createHits
could be externalized so that we don't call it every render
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can it be externalised? if I remember it correctly in vue 2 you only have access to h
in render
's arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering Vue 2 will soon reach EOL, we might want to only support Vue 3 so this wouldn't be a problem.
Else we can make 1 file per version, we'll see what's best !
Only tested with React and Vue 2 for now, the examples still work well.
One problem for now with Vue 2 is that we can't use
DefaultHitComponent
, as you can't callh
with a function component. Maybe Vue 3 will work. Otherwise we can call it as a function as it doesn't have state so it may be fine not to have it as a React/Preact fiber.Next is to try with Preact (expecting TS errors) and Vue 3.
Also has to keep in mind : in React we also pass
div
props, we need to find a way to properly type it for the user, without relying on React types ininstantsearch-jsx
.Update 1 : Vue3 works out of the box, moved Vue2 compat code in its own file and now the same code works for both versions, even
DefaultHitComponent
works ! (save for slots which are still under a condition)Update 2 : For Preact surprisingly types worked easily, however with the way we do templating, we need to have an additional
itemComponent
prop which contains theli
itself :/