Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 24, 2022 05:47 am GMT

Install NextUI in React with Typescript

In this section we will install next ui in react js with typescript using vite tools. NextUI allows you to make beautiful, modern, and fast websites/applications regardless of your design experience, created with React.js and Stitches, based on React Aria and inspired by Vuesax.

Install React Js Using Vite

With NPM:

npm create vite@latest

With Yarn:

yarn create vite

Next, Select react js Project.

nextui with reactjs

Choose Type react-ts for react with typescript.

 Project name:  react-nextui Select a framework:  react? Select a variant:  - Use arrow-keys. Return to submit.  react  react-ts

Move to project and install & run npm.

cd react-nextuinpm installnpm run dev 

Install NEXTUI in React

Inside your React project directory, install NextUI by running either of the following:

yarn add @nextui-org/react# ornpm i @nextui-org/react

Setup NextUI in React

For NextUI to work correctly, you need to set up the NextUIProvider at the root of your application.
src/main.tsx

import React from 'react';import ReactDOM from 'react-dom/client';import App from './App';import './index.css';import { NextUIProvider } from '@nextui-org/react';ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(  <React.StrictMode>    <NextUIProvider>      <App />    </NextUIProvider>  </React.StrictMode>);

Import nextui button in react js.
src/App.tsx

import { useState } from 'react';import reactLogo from './assets/react.svg';import './App.css';import { Button } from '@nextui-org/react';function App() {  const [count, setCount] = useState(0);  return (    <div className="App">      <div>        <a href="https://vitejs.dev" target="_blank">          <img src="/vite.svg" className="logo" alt="Vite logo" />        </a>        <a href="https://reactjs.org" target="_blank">          <img src={reactLogo} className="logo react" alt="React logo" />        </a>      </div>      <h1>Vite + React + NextUI</h1>      <div className="card">        <button onClick={() => setCount((count) => count + 1)}>          count is {count}        </button>        <p>          Edit <code>src/App.tsx</code> and save to test HMR        </p>        <Button>Next UI Button</Button>      </div>      <p className="read-the-docs">        Click on the Vite and React logos to learn more      </p>    </div>  );}export default App;

nextui button with react js using typescript and vite


Original Link: https://dev.to/frontendshape/install-nextui-in-react-with-typescript-3jgd

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To