Installation
Setting up Preline UI in a Next.js project using Tailwind CSS.
Please note that the plugin has been tested with the latest version of the framework (v14.0.1). The framework was installed using the standard npx create-next-app@latest
command.
If you are using your own project structure or a different version, pay attention to the file paths and features of your version!
The React Framework for the Web. If you haven't set up Tailwind CSS yet, check out Next.js 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'), ],}
Create the Preline UI JavaScript loader inside the project, e.g. projects_root_directory/app/components/PrelineScript.tsx
"use client";
import { usePathname } from "next/navigation";
import { useEffect } from "react";
import { IStaticMethods } from "preline/preline";
declare global {
interface Window {
HSStaticMethods: IStaticMethods;
}
}
export default function PrelineScript() {
const path = usePathname();
useEffect(() => {
const loadPreline = async () => {
await import("preline/preline");
window.HSStaticMethods.autoInit();
};
loadPreline();
}, [path]);
return null;
}
Add the Preline UI JavaScript loader to your app entry point, e.g. projects_root_directory/app/layout.tsx
.
...
import PrelineScript from "./components/PrelineScript";
...
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html>
...
<PrelineScript />
</html>
);
}
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.