Use With
Setting up Twind for seamless integration in a React project.
- 🧭 Explore the examples
- 📓 Consult the API reference
- 📜 Read the changelog
This package does not have a dedicated standalone example. Instead, it is used in the following examples:
🤝 Compatibility
@twind/with-react | react |
---|---|
>=1.0.0 <2 | ^16.6.0 , 17.x , 18.x |
📦 Installation
@twind/core
and @twind/with-react
are available on npm and need to be installed together.
🙇 Usage
This package provides several modules that can be used to integrate Twind into your React project. The default export of @twind/with-react
is a function that can be used to setup the twind instance.
The second parameter to install
determines if hashed class names are used. The default used process.env.NODE_ENV === 'production'
which might not work depending on your setup. In that case pass false
to always use non-hashed class names or something like import.meta.env.PROD
if you are using vite.
Besides the default module, the package also provides several subpath exports that can be used to generate server-side rendered styles:
inline
This module can be used to generate server-side rendered styles when using renderToString or renderToStaticMarkup.
pipeableStream
This module can be used to generate server-side rendered styles when using renderToPipeableStream.
This module fully supports Suspense and streaming of HTML with delayed content blocks popping in via inline <script>
tags later. During streaming, styles from each chunk will be collected and merged into the existing styles. If client-side Twind is used it will take over as usual and inject any further dynamic styles once client-side hydration is complete.
readableStream
This module can be used to generate server-side rendered styles when using renderToReadableStream.
This module fully supports Suspense and streaming of HTML with delayed content blocks popping in via inline <script>
tags later. During streaming, styles from each chunk will be collected and merged into the existing styles. If client-side Twind is used it will take over as usual and inject any further dynamic styles once client-side hydration is complete.