What is React? JSX Introduction and Your First Component
What problem React actually solves, how JSX syntax works, and how to build your first component.
When the same stateful logic (like tracking window size, or syncing with localStorage) repeats across two or more components, you can extract it into a custom hook — just write a new function whose name starts with use, and call other hooks inside it.
use (like useLocalStorage) — this is how React and its tooling recognize it and apply the rules correctly.function useLocalStorage(key, initialValue) {
const [value, setValue] = useState(() => {
const saved = localStorage.getItem(key);
return saved !== null ? JSON.parse(saved) : initialValue;
});
useEffect(() => {
localStorage.setItem(key, JSON.stringify(value));
}, [key, value]);
return [value, setValue];
}
function SettingsPage() {
const [darkMode, setDarkMode] = useLocalStorage('darkMode', false);
return (
<label>
<input
type="checkbox"
checked={darkMode}
onChange={(e) => setDarkMode(e.target.checked)}
/>
Dark Mode
</label>
);
}
From the outside, useLocalStorage behaves exactly like useState — the logic behind it (reading/writing localStorage) is hidden away, and can now be reused in any component with a single line.
use... and that calls React hooks internally.What problem React actually solves, how JSX syntax works, and how to build your first component.
Set up a modern React project in seconds with Vite, and understand the resulting folder structure.
Build functional components and pass data from parent to child components using props.