- Home
- Javascript
- Functional Components & State Management
Functional Components & State Management
Contents
Functional Components & State Management
Functional components in React are simple JavaScript functions that return a part of the user interface, typically as JSX. They help break the UI into small, reusable pieces, making the code cleaner and easier to manage. Think of them as building blocks of your app.
State management in React is used to store and manage data that can change over time in a component. The most common way to manage state is with the useState hook, which works as follows:
- First parameter: The initial value of the state.
- Second parameter: A function to update the state value.
Example:
const [count, setCount] = useState(0);
-> count is the current state value (initially 0).
-> setCount is the function used to update the count.-------------------------
const [inputValue, setInputValue] = useState("");Explanation:
A state stores the input text; inputValue holds the current value, and setInputValue updates it whenever the user types, allowing the UI to update in real time.










