With Vite

Setting up PrimeReact in a Vite project.

Working Example#

Quickstart your project with our PrimeReact + Vite template
Use this Vite template pre-configured with PrimeReact to quickly start building your app with ready-to-use UI components and styles.
github.com/primefaces/primereact-examples

Installation#

Install Packages#

Install PrimeReact and a theme package using your favorite package manager:

npm install [email protected] @primeuix/themes

PrimeReactProvider#

Wrap your app with PrimeReactProvider in your main file (like main.tsx or App.tsx). This enables PrimeReact features everywhere in your app:

import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'
import { PrimeReactProvider } from "@primereact/core";
 
...
 
createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <PrimeReactProvider>
        <App />
    </PrimeReactProvider>
  </StrictMode>,
)

Theme#

PrimeReact supports many themes. To use the Aura theme, import it and pass it to the provider:

import Aura from '@primeuix/themes/aura';
import { PrimeReactProvider } from '@primereact/core';
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
 
const theme = {
    preset: Aura
};
 
ReactDOM.createRoot(document.getElementById('root')).render(
    <React.StrictMode>
        <PrimeReactProvider theme={theme}>
            <App />
        </PrimeReactProvider>
    </React.StrictMode>
);

Verify#

To verify that PrimeReact is installed correctly, you can create a simple component such as Button and render it in your application. Each component can be imported and registered individually so that you only include what you use for bundle optimization. Import path is available in the documentation of the corresponding component.

import { Button } from 'primereact/button';
 
export default function VerifyInstallation() {
    return (
        <div className="card flex justify-center">
            <Button>Verify</Button>
        </div>
    );
}

More Tips#

  • You can import and use only the components you need for a smaller bundle size.
  • For icons, custom themes, and advanced setup, see the PrimeReact documentation.

Troubleshooting#

If you encounter issues during installation or setup, check the following:

  • Ensure that you have the latest version of Vite and Node.js installed.
  • Verify that your project structure is correct and that the PrimeReactProvider is properly wrapped around your application.
  • Check the browser console for any errors related to PrimeReact components or themes.
  • If you are using TypeScript, ensure that you have the necessary type definitions installed.
  • Refer to the PrimeReact GitHub repository for more information and support.