An Interest In:
Web News this Week
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
August 24, 2022 05:47 am GMT
Original Link: https://dev.to/frontendshape/install-nextui-in-react-with-typescript-3jgd
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.
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;
Original Link: https://dev.to/frontendshape/install-nextui-in-react-with-typescript-3jgd
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To