Skip to content

Commit

Permalink
Clarify preact/compat integration docs (#4267)
Browse files Browse the repository at this point in the history
* Clarify preact/compat integration

* Create long-lobsters-ring.md

Co-authored-by: Fred K. Schott <fkschott@gmail.com>
  • Loading branch information
bluwy and FredKSchott committed Aug 11, 2022
1 parent 52068e2 commit 5b1facf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-lobsters-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/preact": patch
---

README: Clarify `compat` docs
17 changes: 17 additions & 0 deletions packages/integrations/preact/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ export default defineConfig({

With the `compat` option enabled, the Preact integration will render React components as well as Preact components in your project and also allow you to import React components inside Preact components. Read more in [“Switching to Preact (from React)”](https://preactjs.com/guide/v10/switching-to-preact) on the Preact website.

When importing React component libraries, in order to swap out the `react` and `react-dom` dependencies as `preact/compat`, you can use [`overrides`](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides) to do so.

```js
// package.json
{
"overrides": {
"react": "npm:@preact/compat@latest",
"react-dom": "npm:@preact/compat@latest"
}
}
```

Check out the [`pnpm` overrides](https://pnpm.io/package_json#pnpmoverrides) and [`yarn` resolutions](https://yarnpkg.com/configuration/manifest#resolutions) docs for their respective overrides features.

> **Note**
> Currently, the `compat` option only works for React libraries that export code as ESM. If an error happens during build-time, try adding the library to `vite.ssr.noExternal: ['the-react-library']` in your `astro.config.mjs` file.

## Examples

Expand Down

0 comments on commit 5b1facf

Please sign in to comment.