This website requires JavaScript.
โšก๏ธ CLI & Project Setup
npx create-react-app my-app
npm start
npm run build
npm test
๐Ÿงฉ Component
import React from 'react';

function Hello({ name }) {
  return <h1>Hello, {name}!</h1>;
}

// or arrow function
const Hello = ({ name }) => <h1>Hello, {name}!</h1>;
๐Ÿ”„ State & Effect
import React, { useState, useEffect } from 'react';

function Counter() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    document.title = `Count: ${count}`;
  }, [count]);

  return (
    <button onClick={() => setCount(count + 1)}>
      {count}
    </button>
  );
}
๐Ÿ“ฆ Props
function Welcome({ name }) {
  return <div>Welcome, {name}</div>;
}

<Welcome name="Alice" />
๐Ÿ—๏ธ List & Keys
const items = ['A', 'B', 'C'];
<ul>
  {items.map((item, idx) => (
    <li key={idx}>{item}</li>
  ))}
</ul>
๐Ÿ›ก๏ธ Conditional Rendering
{isLoggedIn ? <Dashboard /> : <Login />}
๐Ÿงช Event Handling
<button onClick={() => alert('Clicked!')}>Click Me</button>
๐Ÿ—‚๏ธ Form Handling
function Form() {
  const [value, setValue] = useState('');
  return (
    <form onSubmit={e => { e.preventDefault(); alert(value); }}>
      <input value={value} onChange={e => setValue(e.target.value)} />
      <button type="submit">Submit</button>
    </form>
  );
}
๐ŸŽจ Styling
// Inline style
<div style={{ color: 'red' }}>Red Text</div>

// CSS Modules
import styles from './App.module.css';
<div className={styles.header}>Header</div>
๐Ÿšฆ Routing (react-router)
npm i react-router-dom
import { BrowserRouter, Route, Routes, Link } from 'react-router-dom';

<BrowserRouter>
  <nav>
    <Link to="/">Home</Link>
    <Link to="/about">About</Link>
  </nav>
  <Routes>
    <Route path="/" element={<Home />} />
    <Route path="/about" element={<About />} />
  </Routes>
</BrowserRouter>
๐Ÿ› ๏ธ Misc
// Fragment
<>
  <h1>Title</h1>
  <p>Paragraph</p>
</>

// Ref
import { useRef } from 'react';
const inputRef = useRef();
<input ref={inputRef} />
Nuxt
Redis