How can you use Preact components inside of a React project? #4236
-
I am currently working on RFUI, a component library similar to Chakra UI. I love Deno's web framework, Fresh, which uses Preact. I plan on using it myself on my projects for the foreseeable future, and I'd like RFUI to work well with it. However, I'd also like it to work with people who are using React, as that's a huge audience. I'm not sure how that'd work though. Looking at this blog post, it seems tricky.
Are there any guides or documentation for how to approach this sort of situation? (This seems like an important question. I expect that people would be much more motivated to write Preact-first components if it was clearly explained how people in React projects would be able to use those components. Although maybe that is misguided. Maybe it isn't actually important to be able to write Preact-first components since Preact makes it easy to use React-first components.) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
That blog post from 2018 about the different JSX factories is outdated. Since we launched Preact 10.x in 2019 Preact ships with both the |
Beta Was this translation helpful? Give feedback.
That blog post from 2018 about the different JSX factories is outdated. Since we launched Preact 10.x in 2019 Preact ships with both the
h()
andcreateElement()
factory out of the box. The main difference when authoring component libraries for React or Preact are the imports. For React you'll be importing fromreact
and for Preact that will bepreact
orpreact/hooks
. Most folks who dual publish for React and Preact publish separate npm packages where the imports are rewritten accordingly. That's pretty much all there is to it.