Using old React versions
Older React Versions
Older React versions are not continuously tested. If you encounter any issues with integration, please contact us for help by joining our Discord.
This guide provides instructions for configuring assistant-ui to work with React 18 or older versions.
React 18
If you're using React 18, you need to update the shadcn/ui components to work with forwardRef
. Specifically, you need to modify the Button component.
Updating the Button Component
Navigate to your button component file (typically /components/ui/button.tsx
) and wrap the Button component with forwardRef
:
Note: If you're using a lower React version (17 or 16), you'll also need to follow the instructions for that version.
React 17
For React 17 compatibility, in addition to the modifications outlined for React 18, you must also include a polyfill for the useSyncExternalStore
hook (utilized by zustand).
Patching Zustand with patch-package
Since the assistant-ui uses zustand internally, which depends on useSyncExternalStore
, you'll need to patch the zustand package directly:
- Install the required packages:
- Add a postinstall script to your package.json:
- Create a patch for zustand by creating a file at
patches/zustand+5.x.x.patch
(replace 5.x.x with the installed zustand version, which you can find by examiningpackage-lock.json
oryarn.lock
) with the following content:
- Run the postinstall script to apply the patch:
This patch replaces the React import in zustand with the polyfill from use-sync-external-store/shim
and comments out the useDebugValue
call which isn't needed.
Note: If you're using React 16, you'll also need to follow the instructions for that version.
React 16
Incomplete Section
This section is incomplete and contributions are welcome. If you're using React 16 and have successfully integrated assistant-ui, please consider contributing to this documentation.
For React 16 compatibility, you need to apply all the steps for React 18 and React 17 above.
Additional Resources
If you encounter any issues with React compatibility, please:
- Check that all required dependencies are installed
- Ensure your component modifications are correctly implemented
- Join our Discord community for direct support