| name | Preact: React Ecosystem Compatibility |
|---|---|
| description | A procedure for using preact/compat to leverage the vast React ecosystem within a Preact application. |
| tier | technology |
| layer | |
| schema | procedure |
To use libraries from the React ecosystem in a Preact project, you MUST configure a path alias in your vite.config.ts to point react and react-dom imports to preact/compat.
- Open
vite.config.ts: Locate and open your Vite configuration file. - Add the
resolveKey: Inside thedefineConfigobject, add aresolvekey if one does not already exist. - Configure the
aliasObject: Within theresolveobject, add analiasobject. - Set the Aliases: The
aliasobject MUST contain two key-value pairs:'react': 'preact/compat''react-dom': 'preact/compat'
- This alias MUST be in place before attempting to install and use a React-specific library.
- You must be aware that
preact/compatadds a small amount of overhead to your bundle size, which is the trade-off for gaining access to the React ecosystem.