React With useState Hook
Allows you to add state to your functional components. The useState Hook returns an array with two elements: the current state value and a function to update the state.
How To Define State
import { useState } from 'react'
const [ data , setData ] = useState ( init )
Setup useSate Hook
- < StrictMode >
- < BrowserRouter >
- < App />
- < /BrowserRouter >
- < /StrictMode >
Implement useSate Hook
- < Routes >
- < Route path="/" element={< Home />} />
- < Route path="/page" element={< Page />} />
- < Route path="/profile" element={< Profile />} />
- < Route path="*" element={< h1 >Page 404< /h1 >} />
- < Routes >
When to Use React.js
- You want maximum flexibility and control over your project.
- You are building a highly interactive single-page application (SPA).
- You are comfortable setting up your own routing, state management, and other tools.