-
Notifications
You must be signed in to change notification settings - Fork 8
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
Use client #12
Use client #12
Conversation
Because Microbundle and Rollup don't support 'use client'
@@ -15,8 +17,7 @@ function DangerouslySetHtmlContent({ html, dangerouslySetInnerHTML, ...rest }) { | |||
divRef.current.appendChild(slotHtml) // Append the new content | |||
}, [html, divRef]) | |||
|
|||
// eslint-disable-next-line react/react-in-jsx-scope | |||
return <div {...rest} ref={divRef} /> | |||
return createElement('div', { ...rest, ref: divRef }) |
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 not transpiled anymore but it's not a problem, spread is supported everywhere now:
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.
The arrow function in the useEffect above is also not transpiled anymore but this is supported everywhere:
- https://caniuse.com/arrow-functions
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#browser_compatibility
Same for const
:
@tkrotoff Thanks a lot!!! this is really really helpful, so let me get this straight then, you're saying that we no longer need to build the code right? so a simple |
Yes that's the idea.
The only edge cases I can think of are:
|
Yeah that why I though, well I just bump the version and publish it, I wonder if the |
To be compatible with React Server Components, the 'use client' directive is needed, see https://react.dev/reference/react/use-client
Problem: Microbundle and Rollup don't support 'use client'
Solution: given this source code is very small, use
createElement
and CJS directly.Then no need for a bundler, the code is directly compatible with everything (CJS, ESM).
I carefully checked the example works, the tests pass and using my own app which uses this package, that nothing is broken.
Here the npm package it generates: