Installation
Setting up Preline UI in a React project using Tailwind CSS.
postcss-import
.
For a more flexible and controlled development experience, especially regarding Tailwind and PostCSS configurations, we suggest opting for alternatives like Next.js or Remix. These tools offer a similar or enhanced developer experience compared to Create React App, but with added flexibility.
Please note that the plugin has been tested with the latest version of the framework (v18.2.0). The framework was installed using the standard npx create-react-app@latest <project-name> --template typescript
command.
If you are using your own project structure or a different version, pay attention to the file paths and features of your version!
A framework for building web user interfaces. If you haven't set up Tailwind CSS yet, check out React Tailwind CSS installation guides.
Install preline
via npm or yarn.
// Terminal or Shellnpm install preline // or yarn add preline
Add the path to Preline UI JavaScript files in your tailwind.config.js
file.
// tailwind.config.jsmodule.exports = { content: [ './node_modules/preline/preline.js', ], plugins: [ require('preline/plugin'), ],}
Add code that reinitializes the components every time when app is mounted or page was changed projects_root_directory/src/App.tsx
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import "preline/preline";
import { IStaticMethods } from "preline/preline";
declare global {
interface Window {
HSStaticMethods: IStaticMethods;
}
}
...
function App() {
const location = useLocation();
useEffect(() => {
window.HSStaticMethods.autoInit();
}, [location.pathname]);
return (
...
);
}
export default App;
Check out this section for community-shared tips and tricks. It's a spot for finding those handy hacks and solutions that enhance your experience with Preline UI.