# React

# WebSocket or Socket io in react

<div class="WaaZC" id="bkmrk-the-choice-between-u" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc" data-hveid="CAMQAQ" data-ved="2ahUKEwiZ1OnA5aqRAxUo4zgGHQBsGE4Qo_EKegQIAxAB" style="margin: 0px 0px 10px;"><span data-huuid="2996336202520041438">The choice between using raw WebSockets or [Socket.IO](https://socket.io/) in a React application depends on the specific requirements of the project.</span></div></div></div><div class="WaaZC" id="bkmrk-websockets%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CAUQAQ" data-ved="2ahUKEwiZ1OnA5aqRAxUo4zgGHQBsGE4Qo_EKegQIBRAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="2996336202520042992">WebSockets:</span></div></div></div><div class="WaaZC" id="bkmrk-pros%3A-provides-a-dir" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 0px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="2996336202520041227">**Pros:**</span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); display: inline;">
    - <span data-huuid="2996336202520039462">Provides a direct, low-level protocol for real-time communication, offering maximum control and flexibility.</span>
    - <span data-huuid="2996336202520041016">Minimal overhead, leading to potentially higher performance in certain scenarios.</span>
    - <span data-huuid="2996336202520042570">Broad interoperability with various WebSocket servers.</span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="2996336202520040028">**Cons:**</span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); display: inline;">
    - <span data-huuid="2996336202520042359">Requires more boilerplate code for features like reconnection, error handling, and message buffering.</span>
    - <span data-huuid="2996336202520039817">Steeper learning curve for managing connection states and potential issues.</span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="2996336202520041371">**Use Cases:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); display: inline;"><span data-huuid="2996336202520042148">Simple, high-performance applications where fine-grained control over the connection is crucial, such as game data updates or stock tickers.</span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-socket.io%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CB8QAQ" data-ved="2ahUKEwiZ1OnA5aqRAxUo4zgGHQBsGE4Qo_EKegQIHxAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="17132968970867578895">[Socket.IO](https://socket.io/):</span></div></div></div><div class="WaaZC" id="bkmrk-pros%3A-built-on-top-o" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 0px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="17132968970867577620">**Pros:**</span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); display: inline;">
    - <span data-huuid="17132968970867580441">Built on top of WebSockets, providing a higher-level abstraction with built-in features like automatic reconnection, event-based communication, and fallbacks (like HTTP long-polling) for environments where WebSockets are not supported.</span>
    - <span data-huuid="17132968970867579591">Simplified development with a feature-rich API and abstractions for common real-time functionalities.</span>
    - <span data-huuid="17132968970867578741">Easier to adopt, especially for developers familiar with Node.js.</span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="17132968970867577891">**Cons:**</span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); display: inline;">
    - <span data-huuid="17132968970867580712">Adds some overhead due to its feature set and metadata, potentially leading to slightly larger message sizes.</span>
    - <span data-huuid="17132968970867579862">Limited interoperability with non-Socket.IO WebSocket servers.</span>
    - <span data-huuid="17132968970867579012">Not designed for global scale in the same way as raw WebSockets.</span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="17132968970867578162">**Use Cases:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); display: inline;"><span data-huuid="17132968970867577737">Applications requiring robust real-time features like chat applications, collaborative editing, real-time analytics, and where ease of development and built-in reliability are priorities.</span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-in-react%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CDkQAQ" data-ved="2ahUKEwiZ1OnA5aqRAxUo4zgGHQBsGE4Qo_EKegQIORAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="13129251272164368110">In React:</span></div></div></div><div class="WaaZC" id="bkmrk-you-can-use-the-nati" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <span data-huuid="13129251272164367385">You can use the native browser WebSocket API directly or leverage libraries like `react-use-websocket` for simplified integration with React's lifecycle and hooks.</span>
- <span data-huuid="13129251272164368267">For [Socket.IO](https://socket.io/), you can use the `socket.io-client` library and manage the connection within your React components, potentially using React Context or custom hooks for global access.</span>

</div></div><div class="WaaZC" id="bkmrk-conclusion%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CEIQAQ" data-ved="2ahUKEwiZ1OnA5aqRAxUo4zgGHQBsGE4Qo_EKegQIQhAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="15426272183334331175">Conclusion:</span></div></div></div><div class="WaaZC" id="bkmrk-choose-websockets-if" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <span data-huuid="15426272183334333852">Choose WebSockets if you need absolute control, minimal overhead, and are comfortable implementing features like reconnection and error handling yourself.</span>
- <span data-huuid="15426272183334332906">Choose [Socket.IO](https://socket.io/) if you prioritize ease of development, automatic handling of common real-time challenges, and built-in features like reconnection and event-based communication.</span>

</div></div><div id="bkmrk-websocket-sample-cod"><div class="WaaZC" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc uP58nb rWIipd" data-hveid="CAQQAQ" data-ved="2ahUKEwjo28qF5qqRAxUo4zgGHQBsGE4Qo_EKegQIBBAB" role="heading" style="margin: 0px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="858667837331752369">WebSocket Sample Code in React</span></div></div></div><div class="WaaZC" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc" data-hveid="CAYQAQ" data-ved="2ahUKEwjo28qF5qqRAxUo4zgGHQBsGE4Qo_EKegQIBhAB" style="margin: 10px 0px;"><span data-huuid="858667837331753975">Using the native WebSocket API in a React component:</span></div></div></div><div class="WaaZC" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc" style="border-image: none 100% / 1 / 0 stretch; border-radius: 8px; font-size: 14px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); margin-bottom: 20px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="zYSUYd" style="display: flex; flex-direction: row; overflow: hidden; border-radius: 8px 8px 0px 0px;"><div class="FS7GEb" style="display: flex; flex-direction: column; flex-grow: 1; min-width: 38%; width: 629.381px;"><div class="dDrxod" style="height: 34px; display: flex; justify-content: space-between; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border-bottom: 1.2px solid rgb(169, 172, 170);"><div class="x7ndcb" style="padding-left: 16px; display: flex; align-items: center; color: rgb(10, 10, 10);">Code</div><div aria-live="polite" class="WDoJJe" style="margin-right: 4px; display: flex; align-items: center;"><button aria-label="Copy code to clipboard" class="hqI3tf B4zsNc" data-ved="2ahUKEwjo28qF5qqRAxUo4zgGHQBsGE4Q9MILegQIAhAB" role="button" style="margin: 0px 2px; background: none; height: 34px; border: none; color: rgb(5, 40, 97); position: relative; top: 2px; outline: 0px;" tabindex="0" title="Copy"><span class="z1asCe wm4nBd" style="display: inline-block; fill: currentcolor; height: 20px; line-height: 20px; position: relative; width: 20px;"><svg aria-hidden="true" enable-background="new 0 0 24 24" focusable="false" height="24" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><g><rect fill="none" height="24" width="24"></rect></g><g><path d="M16,20H5V6H3v14c0,1.1,0.9,2,2,2h11V20z M20,16V4c0-1.1-0.9-2-2-2H9C7.9,2,7,2.9,7,4v12c0,1.1,0.9,2,2,2h9 C19.1,18,20,17.1,20,16z M18,16H9V4h9V16z"></path></g></svg></span></button></div></div></div></div><div class="QQjpRc" style="display: flex; flex-direction: row; overflow: hidden; border-radius: 0px 0px 8px 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5);"><div class="FS7GEb" jsname="zEXxAd" style="display: flex; flex-direction: column; flex-grow: 1; min-width: 38%; width: 629.381px;"></div></div></div></div></div></div></div>```
import React, { useEffect, useState } from 'react';

function WebSocketComponent() {
  const [messages, setMessages] = useState([]);
  const [inputValue, setInputValue] = useState('');
  const [ws, setWs] = useState(null);

  useEffect(() => {
    const newWs = new WebSocket('ws://localhost:8080'); // Replace with your WebSocket server URL

    newWs.onopen = () => {
      console.log('WebSocket connected');
    };

    newWs.onmessage = (event) => {
      setMessages((prevMessages) => [...prevMessages, event.data]);
    };

    newWs.onclose = () => {
      console.log('WebSocket disconnected');
    };

    newWs.onerror = (error) => {
      console.error('WebSocket error:', error);
    };

    setWs(newWs);

    return () => {
      newWs.close();
    };
  }, []);

  const sendMessage = () => {
    if (ws && ws.readyState === WebSocket.OPEN) {
      ws.send(inputValue);
      setInputValue('');
    }
  };

  return (
    <div>
      <h1>WebSocket Chat</h1>
      <div>
        {messages.map((msg, index) => (
          <p key={index}>{msg}</p>
        ))}
      </div>
      <input
        type="text"
        value={inputValue}
        onChange={(e) => setInputValue(e.target.value)}
      />
      <button onClick={sendMessage}>Send</button>
    </div>
  );
}

export default WebSocketComponent;
```

<div id="bkmrk-socket.io%C2%A0sample-cod"><div class="WaaZC" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc" style="border-image: none 100% / 1 / 0 stretch; border-radius: 8px; font-size: 14px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); margin-bottom: 20px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="QQjpRc" style="display: flex; flex-direction: row; overflow: hidden; border-radius: 0px 0px 8px 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5);"><div class="FS7GEb" jsname="zEXxAd" style="display: flex; flex-direction: column; flex-grow: 1; min-width: 38%; width: 629.381px;"></div></div></div></div></div></div><div class="WaaZC" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc uP58nb rWIipd" data-hveid="CA0QAQ" data-ved="2ahUKEwjo28qF5qqRAxUo4zgGHQBsGE4Qo_EKegQIDRAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="8539701963755056614">[Socket.IO](https://socket.io/) Sample Code in React</span></div></div></div><div class="WaaZC" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc" data-hveid="CA4QAQ" data-ved="2ahUKEwjo28qF5qqRAxUo4zgGHQBsGE4Qo_EKegQIDhAB" style="margin: 10px 0px;"><span data-huuid="8539701963755053808">Using the [Socket.IO](https://socket.io/) client library in a React component:</span></div></div></div><div class="WaaZC" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc" style="border-image: none 100% / 1 / 0 stretch; border-radius: 8px; font-size: 14px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); margin-bottom: 20px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="zYSUYd" style="display: flex; flex-direction: row; overflow: hidden; border-radius: 8px 8px 0px 0px;"><div class="FS7GEb" style="display: flex; flex-direction: column; flex-grow: 1; min-width: 38%; width: 629.381px;"><div class="dDrxod" style="height: 34px; display: flex; justify-content: space-between; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border-bottom: 1.2px solid rgb(169, 172, 170);"><div class="x7ndcb" style="padding-left: 16px; display: flex; align-items: center; color: rgb(10, 10, 10);">Code</div><div aria-live="polite" class="WDoJJe" style="margin-right: 4px; display: flex; align-items: center;"><button aria-label="Copy code to clipboard" class="hqI3tf B4zsNc" data-ved="2ahUKEwjo28qF5qqRAxUo4zgGHQBsGE4Q9MILegQICxAB" role="button" style="margin: 0px 2px; background: none; height: 34px; border: none; color: rgb(5, 40, 97); position: relative; top: 2px; outline: 0px;" tabindex="0" title="Copy"><span class="z1asCe wm4nBd" style="display: inline-block; fill: currentcolor; height: 20px; line-height: 20px; position: relative; width: 20px;"><svg aria-hidden="true" enable-background="new 0 0 24 24" focusable="false" height="24" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><g><rect fill="none" height="24" width="24"></rect></g><g><path d="M16,20H5V6H3v14c0,1.1,0.9,2,2,2h11V20z M20,16V4c0-1.1-0.9-2-2-2H9C7.9,2,7,2.9,7,4v12c0,1.1,0.9,2,2,2h9 C19.1,18,20,17.1,20,16z M18,16H9V4h9V16z"></path></g></svg></span></button></div></div></div></div><div class="QQjpRc" style="display: flex; flex-direction: row; overflow: hidden; border-radius: 0px 0px 8px 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5);"><div class="FS7GEb" jsname="zEXxAd" style="display: flex; flex-direction: column; flex-grow: 1; min-width: 38%; width: 629.381px;"></div></div></div></div></div></div></div>```
import React, { useEffect, useState } from 'react';
import io from 'socket.io-client'; // Install with: npm install socket.io-client

const socket = io('http://localhost:3001'); // Replace with your Socket.IO server URL

function SocketIOComponent() {
  const [messages, setMessages] = useState([]);
  const [inputValue, setInputValue] = useState('');

  useEffect(() => {
    socket.on('connect', () => {
      console.log('Socket.IO connected');
    });

    socket.on('message', (message) => {
      setMessages((prevMessages) => [...prevMessages, message]);
    });

    socket.on('disconnect', () => {
      console.log('Socket.IO disconnected');
    });

    return () => {
      socket.off('connect');
      socket.off('message');
      socket.off('disconnect');
    };
  }, []);

  const sendMessage = () => {
    socket.emit('message', inputValue); // 'message' is the event name
    setInputValue('');
  };

  return (
    <div>
      <h1>Socket.IO Chat</h1>
      <div>
        {messages.map((msg, index) => (
          <p key={index}>{msg}</p>
        ))}
      </div>
      <input
        type="text"
        value={inputValue}
        onChange={(e) => setInputValue(e.target.value)}
      />
      <button onClick={sendMessage}>Send</button>
    </div>
  );
}

export default SocketIOComponent;
```

# waypoints.min.js

<div class="WaaZC" id="bkmrk-waypoints.min.js-ref"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CAMQAQ" data-ved="2ahUKEwij7aW7nLCRAxUKSmwGHS6UCOIQo_EKegQIAxAB"><span data-huuid="2523922895047217619">`waypoints.min.js` refers to the minified version of the Waypoints JavaScript library. </span></div></div></div><div class="WaaZC" id="bkmrk-waypoints-is-a-javas"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc uP58nb MNX06c" data-hveid="CAUQAQ" data-ved="2ahUKEwij7aW7nLCRAxUKSmwGHS6UCOIQo_EKegQIBRAB"><span data-huuid="2523922895047219917">Waypoints is a JavaScript library designed to make it easy to trigger functions when a user scrolls to a specific element on a webpage. </span><span data-huuid="2523922895047221066">It allows developers to create interactive experiences based on scroll position, such as: </span></div></div></div><div class="WaaZC" id="bkmrk-lazy-loading-content"><div class="RJPOee EIJn2" style="animation: none !important;">- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="2523922895047220417">**Lazy loading content:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="2523922895047217470">Loading images or other content only when they become visible in the viewport. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="2523922895047219768">**Animations:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="2523922895047220917">Triggering CSS animations or JavaScript-based animations when an element enters or exits the viewport. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="2523922895047219119">**Sticky elements:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="2523922895047220268">Making elements "stick" to the top of the screen when scrolled past a certain point. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="2523922895047218470">**Navigation updates:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="2523922895047219619">Highlighting current sections in a navigation menu as the user scrolls through the page. </span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-minification-is-a-pr"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CBkQAQ" data-ved="2ahUKEwij7aW7nLCRAxUKSmwGHS6UCOIQo_EKegQIGRAB"><span data-huuid="12198398430281155419">Minification is a process that removes all unnecessary characters from JavaScript source code without altering its functionality. </span><span data-huuid="12198398430281154966">This includes removing whitespace, comments, and using shorter variable names and functions. </span><span data-huuid="12198398430281158609">The `.min.js` extension indicates that the file has undergone this minification process, resulting in a smaller file size and faster loading times in web applications.<span class="pjBG2e" data-cid="6ea308bb-8ae0-432c-b6a6-c17c585242e9"><span class="UV3uM"> </span></span></span><div class="NPrrbc" data-cid="6ea308bb-8ae0-432c-b6a6-c17c585242e9" data-uuids="12198398430281155419,12198398430281154966,12198398430281158609"><div aria-label="View related links" class="BMebGe btku5b LwdV0e FR7ZSc OJeuxf" data-hveid="CBsQAQ" data-ved="2ahUKEwij7aW7nLCRAxUKSmwGHS6UCOIQ3fYKegQIGxAB" jsaction="KjsqPd" jsname="HtgYJd" role="button" tabindex="0"><div class="niO4u"><span class="TwMgNb Hkv2Pe"><span class="iPjmzb Sorfoc gNGSDf"><span class="z1asCe Sb7k4e" style="height: 18px; line-height: 18px; width: 18px;"><svg aria-hidden="true" focusable="false" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"></svg></span></span></span></div></div></div></div></div></div><div class="WaaZC" id="bkmrk-"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CBkQAQ" data-ved="2ahUKEwij7aW7nLCRAxUKSmwGHS6UCOIQo_EKegQIGRAB">  
</div></div></div><div class="WaaZC" id="bkmrk-in-essence%2C-waypoint"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CCAQAQ" data-ved="2ahUKEwij7aW7nLCRAxUKSmwGHS6UCOIQo_EKegQIIBAB"><span data-huuid="969731735847831098">In essence, `waypoints.min.js` is the optimized, production-ready version of the Waypoints library, ready for use in web projects where scroll-based interactions are desired.</span></div></div></div>

# jquery.colorbox.js

<div class="WaaZC" id="bkmrk-jquery.colorbox.js-r"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CAUQAQ" data-ved="2ahUKEwjY-fHHnLCRAxV7ZWwGHclUC28Qo_EKegQIBRAB"><span data-huuid="2198991443076037787">`jquery.colorbox.js` refers to the ColorBox jQuery plugin, a lightweight and customizable lightbox solution. </span><span data-huuid="2198991443076036554">It is designed to display various types of content, including images, image groups (slideshows), AJAX content, inline HTML, and iframed content, in a modal window or overlay on a webpage. </span></div></div><div class="rPeykc" data-hveid="CAUQAQ" data-ved="2ahUKEwjY-fHHnLCRAxV7ZWwGHclUC28Qo_EKegQIBRAB"></div></div><div class="WaaZC" id="bkmrk-key-features-and-usa"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CAYQAQ" data-ved="2ahUKEwjY-fHHnLCRAxV7ZWwGHclUC28Qo_EKegQIBhAB" role="heading">**<span data-huuid="2198991443076038184">Key features and usage: </span>**</div></div></div><div class="WaaZC" id="bkmrk-lightbox-functionali"><div class="RJPOee EIJn2" style="animation: none !important;">- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="2198991443076038581">**Lightbox functionality:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="2198991443076037348">ColorBox provides the classic lightbox effect, dimming the background and displaying content in a central, interactive overlay. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="2198991443076034882">**Content types:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="2198991443076037745">It supports a wide range of content, making it versatile for different web development needs. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="2198991443076035279">**Customization:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="2198991443076038142">The plugin offers numerous options for customization through an object of key/value pairs passed during initialization. </span><span data-huuid="2198991443076036909">This allows control over appearance, behavior, and responsiveness. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="2198991443076038539">**Integration with jQuery:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="2198991443076037306">As a jQuery plugin, it extends the functionality of the jQuery library, requiring jQuery to be included in the HTML document before `jquery.colorbox.js`. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="2198991443076034840">**Implementation:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="2198991443076037703">To use ColorBox, you typically include the `jquery.min.js` (or similar jQuery core file) and `jquery.colorbox-min.js` (or `jquery.colorbox.js`) files in the `<head>` section of your HTML, along with the associated `colorbox.css` stylesheet for styling. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="2198991443076035237">**Basic usage example:** </span></div><div class="vM0jzc" style="display: inline;">  
    </div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-javascript"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">JavaScript</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
    $(document).ready(function(){
        $(".example-link").colorbox({
            rel: 'gallery', // groups items for a slideshow
            transition: 'fade', // animation type
            width: '80%', // width of the lightbox
            height: '80%' // height of the lightbox
        });
    });
```

# main.jsx

<span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In React applications, </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">main.jsx</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> (or sometimes </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">index.jsx</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">) typically serves as the entry point of the application. It is the file where the main React component, often named </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">App</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, is imported and then rendered into the root element of the HTML document.</span>

<span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Here's a breakdown of its typical function:</span>

- <span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Importing React and ReactDOM:</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> It imports the necessary libraries for building and rendering React components.</span>
- <span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Importing the main component:</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> It imports the top-level component of the application, usually </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">App.jsx</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, which encapsulates the entire user interface.</span>
- <span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Locating the root HTML element:</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> It identifies the HTML element (typically a </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">div</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> with the ID </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">root</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">) within </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">index.html</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> where the React application will be mounted.</span>
- <span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Rendering the application:</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> It uses </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ReactDOM.createRoot()</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> and </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">render()</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> to inject the main React component into the specified root HTML element, effectively making the React application visible in the browser.</span>

<span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Essentially, </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">main.jsx</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> acts as the bridge between your React components and the actual web page, initiating the rendering process and bringing your application to life.</span>

# html-react-parser

<div class="WaaZC" id="bkmrk-html-react-parser-is"><div class="rPeykc" data-hveid="CCYQAQ" data-ved="2ahUKEwjB6pOXoLCRAxWFRmwGHVy4IA8Qo_EKegQIJhAB"><span data-huuid="16464151239809186746">`html-react-parser` is a JavaScript library designed to convert an HTML string into one or more React elements. </span><span data-huuid="16464151239809184451">This utility is particularly useful in React applications where dynamic content, often received as raw HTML from a server or a Content Management System (CMS), needs to be rendered within the React component tree. </span></div><div class="rPeykc" data-hveid="CCYQAQ" data-ved="2ahUKEwjB6pOXoLCRAxWFRmwGHVy4IA8Qo_EKegQIJhAB"></div></div><div class="WaaZC" id="bkmrk-key-features-and-usa"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCAQAQ" data-ved="2ahUKEwjB6pOXoLCRAxWFRmwGHVy4IA8Qo_EKegQIIBAB" role="heading">**<span data-huuid="16464151239809183957">Key Features and Usage: </span>**</div></div><div class="WaaZC" id="bkmrk-conversion-of-html-s">- <span data-huuid="16464151239809185264">**Conversion of HTML strings to React elements:** </span><span data-huuid="16464151239809187065">The primary function of `html-react-parser` is to take an HTML string as input and transform it into a structure that React can understand and render. </span>

</div><div class="WaaZC" id="bkmrk-code"><div class="bsmXxe" id="bkmrk-code-1" role="none"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
    import parse from 'html-react-parser';

    const MyComponent = () => {
      const htmlString = '<div><h1>Hello, World!</h1><p>This is some dynamic content.</p></div>';
      return <div>{parse(htmlString)}</div>;
    };
```

<div class="WaaZC" id="bkmrk-server-side-renderin"><div class="bsmXxe" id="bkmrk-server-side-renderin-1" role="none"><div class="bsmXxe" id="bkmrk-server-side-renderin-2" role="none"><div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="13316290780724241067">**Server-Side Rendering (SSR) and Client-Side Usage:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="13316290780724241188">The library is compatible with both server-side (Node.js) and client-side (browser) environments, enabling consistent rendering across different application architectures. </span></div></div></div></div></div><div class="bsmXxe" id="bkmrk-element-replacement%3A" role="none"><div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="13316290780724241430">**Element Replacement:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="13316290780724241551">It provides an option to replace specific HTML elements with custom React components, offering flexibility in how parsed content is displayed. </span></div></div></div></div></div></div></div><div class="WaaZC" id="bkmrk-code-2"><div class="bsmXxe" id="bkmrk-code-3" role="none"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
    import parse from 'html-react-parser';

    const MyComponent = () => {
      const htmlString = '<p>This is a paragraph with a <span>special</span> word.</p>';
      const options = {
        replace: (domNode) => {
          if (domNode.name === 'span') {
            return <strong style={{ color: 'blue' }}>{domNode.children[0].data}</strong>;
          }
        },
      };
      return <div>{parse(htmlString, options)}</div>;
    };
```

<div class="WaaZC" id="bkmrk-important-considerat"><div class="bsmXxe" id="bkmrk-important-considerat-1" role="none"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CGUQAQ" data-ved="2ahUKEwjB6pOXoLCRAxWFRmwGHVy4IA8Qo_EKegQIZRAB" role="heading">**<span data-huuid="13316290780724241793">Important Considerations: </span>**</div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CGUQAQ" data-ved="2ahUKEwjB6pOXoLCRAxWFRmwGHVy4IA8Qo_EKegQIZRAB" role="heading"></div></div></div><div class="WaaZC" id="bkmrk-security-%28xss-safety"><div class="bsmXxe" id="bkmrk-security-%28xss-safety-1" role="none"><div class="bsmXxe" id="bkmrk-security-%28xss-safety-2" role="none"><div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="13316290780724242156">**Security (XSS Safety):** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="13316290780724242277">`html-react-parser` does not inherently provide XSS (Cross-Site Scripting) protection or HTML sanitization. </span><span data-huuid="13316290780724242398">Developers must implement their own sanitization measures when dealing with untrusted HTML content to prevent security vulnerabilities. </span></div></div></div></div></div><div class="bsmXxe" id="bkmrk-inline-event-handler" role="none"><div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="13316290780724242640">**Inline Event Handlers:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="13316290780724242761">Inline event handlers (e.g., `onclick`) within the HTML string are parsed as strings and are not directly evaluated as functions by the browser for security reasons. </span></div></div></div></div></div><div class="bsmXxe" id="bkmrk-performance%3A-while-g" role="none"><div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="13316290780724243003">**Performance:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="13316290780724243124">While generally efficient, parsing very large or complex HTML strings can impact performance, and optimization strategies might be necessary in such cases.</span></div></div></div></div></div></div></div>

# Storybook

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk-storybook-is-an-open" jsaction="rcuQ6b:&pXoq0d_7|npT2md" jscontroller="zcfIf" jsuid="pXoq0d_7" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 0px 0px 20px; color: rgb(10, 10, 10); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Storybook is an open-source **[UI development tool](https://www.google.com/search?q=UI+development+tool&sca_esv=8ab2282fee241d3c&sxsrf=AE3TifPSVfYbyCUp3jW67zu5Rmfn0cxecA%3A1765433073999&ei=8V46afnXPIzRg8UPwdPPwA8&ved=2ahUKEwidha_d7rSRAxXzzjgGHSliKisQgK4QegQIARAD&uact=5&oq=storybook+tool++bsics&gs_lp=Egxnd3Mtd2l6LXNlcnAiFXN0b3J5Ym9vayB0b29sICBic2ljczIHECEYoAEYCjIHECEYoAEYCjIFECEYnwVI7B5Q3wtY9BtwAXgBkAEAmAGaAqABwQuqAQUwLjMuNLgBA8gBAPgBAZgCCKACtwzCAgoQABiwAxjWBBhHwgIGEAAYFhgewgIFECEYoAGYAwCIBgGQBgiSBwcxLjMuMy4xoAftGrIHBzAuMy4zLjG4B6oMwgcHMi01LjIuMcgHRoAIAA&sclient=gws-wiz-serp&mstk=AUtExfCJFd01ZrJ1TunK3o6YLF5fwWOkW19cNKst9C_zP3vrwcxuG4uoTKNFj0x9vkRWD6A-NE4Vwlpd66S10E46LtNRuXJzT3uwUGhspzfO2Ju5xUUfNoLzM2qjCzHwlGVHKtDiJ9QGlK5uA6cjH24vtNEe6zQIjP3fDQw9XwAHgzcYV-Wxr5oLeDtvZfYtS3oarFSB5m91qh9ANSAhwc1_JlmAywDQgtoKgbEd3foWwVj62ZKPx8-p2GmIdX2lm5nHnp-mNZiOGY2N2Xopg-POfcE1&csui=3)** that lets developers build, test, and document components in an isolated sandbox environment, separate from the main application, ensuring consistency and efficiency. Its basics involve creating "stories" (different states of a component), running the Storybook server (often `npm run storybook`), and using its interface to interactively adjust props, view different states (like error or loading), and leverage add-ons for testing (accessibility, visual regression) and documentation.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="pXoq0d_g,pXoq0d_h,pXoq0d_i"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="4e4a6765-8074-4ed9-9bfa-7c514084af24" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQye0OegQIARAE" data-wiz-attrbind="disabled=pXoq0d_g/C5gNJc;class=pXoq0d_g/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Y3BBE" data-hveid="CAIQAA" data-processed="true" data-sfc-cp="" id="bkmrk-this-video-provides-" jsaction="rcuQ6b:&pXoq0d_q|npT2md" jscontroller="zcfIf" jsuid="pXoq0d_q" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 10px 0px 20px; color: rgb(10, 10, 10); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">This video provides a quick overview of Storybook: <div class="" data-processed="true" data-wiz-uids="pXoq0d_s,pXoq0d_t" jscontroller="uDeH3" jsuid="pXoq0d_r"><div data-hveid="CAIQAQ" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQ-bUQegQIAhAB"><div data-processed="true"><div class="Q2WBBe" data-processed="true" jsuid="pXoq0d_t" style="container-type: inline-size; display: flex; flex-direction: column; background-color: rgb(243, 245, 246); margin-top: 12px; border-radius: 16px;"><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQypYSegQIAhAC" jsuid="pXoq0d_s" style="overflow: hidden; position: relative; border-radius: 16px 16px 0px 0px; width: 631.987px; height: 353.906px; outline: 0px;" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="pXoq0d_v" jsaction="rcuQ6b:&pXoq0d_u|npT2md" jscallback="gfNXHe:&pXoq0d_r:U8wGUb" jscontroller="wMmv4c" jsuid="pXoq0d_u" style="width: 631.987px; height: 353.906px;"><div class="nrdPJf" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQtbEQegQIAhAD" jsaction="click:&pXoq0d_u|T2P31d" jsuid="pXoq0d_v" role="button" style="cursor: pointer; width: 631.987px; height: 353.906px; outline: 0px;" tabindex="0"><div aria-label="Play" class="mxefw" data-processed="true" style="height: 44px; left: calc(50% - 22px); position: absolute; top: calc(50% - 22px); width: 44px;"><svg fill="none" height="44" viewbox="0 0 44 44" width="44" xmlns="http://www.w3.org/2000/svg"><rect fill="black" fill-opacity="0.6" height="44" rx="22" width="44"></rect><path d="M17 15.5222V28.4772C17 29.5554 18.2017 30.1986 19.0988 29.6005L28.8151 23.123C29.6166 22.5886 29.6166 21.4108 28.8151 20.8764L19.0988 14.3989C18.2017 13.8008 17 14.444 17 15.5222Z" fill="white"></path></svg></div><div class="Pa4wsd YkW4Kb" data-processed="true" style="align-items: center; display: flex; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.6); border-radius: 100px; font-size: 12px; gap: 4px; left: 12px; line-height: 1.33; position: absolute; bottom: 12px; padding: 2px 8px; z-index: 2;"><span class="zY18Ie" data-processed="true" style="color: rgb(255, 255, 255);">02:19</span></div><div class="dumoDb YkW4Kb" data-processed="true" style="z-index: 2; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.6); border-radius: 100px; cursor: pointer; position: absolute; right: 14px; top: 12px;"><div class="CaQWce" data-processed="true" jscontroller="sRLmTc" jsuid="pXoq0d_w" style="align-items: center; color: rgb(255, 255, 255); display: flex; height: 20px; justify-content: center; transform: rotate(45deg); width: 20px;"><svg fill="currentColor" height="18px" viewbox="0 -960 960 960" width="18px" xmlns="http://www.w3.org/2000/svg"><path d="M480-120 300-300l58-58 122 122 122-122 58 58-180 180ZM358-598l-58-58 180-180 180 180-58 58-122-122-122 122Z" fill="currentColor"></path></svg></div></div></div></div></div><div data-processed="true">[<div class="RhEuY" data-processed="true" style="display: flex; padding: 16px 12px 12px; gap: 8px; align-items: center;"><div class="SWvopd" data-processed="true" jscontroller="aNJZAb" jsuid="pXoq0d_x" style="height: fit-content; width: fit-content; margin-bottom: 2px; position: relative;"><div class="Lki2rc" data-processed="true" style="width: 20px; height: 20px; line-height: 20px;"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="pXoq0d_y" style="width: 19.9875px; height: 19.9875px; line-height: 16px; display: flex; flex-shrink: 0; align-items: center; justify-content: center; overflow: hidden; background-color: rgb(255, 255, 255); border-radius: 50%;"></div></div><div class="JccCTc xG6cCf" data-processed="true" style="position: absolute; bottom: -4px; right: -4px; border-radius: 50%; line-height: 10px; padding: 2px; background-color: rgb(255, 255, 255); width: 10px; height: 10px;"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="pXoq0d_z" style="width: 9.99375px; height: 9.99375px; line-height: 16px; display: flex; flex-shrink: 0; align-items: center; justify-content: center; overflow: hidden; background-color: rgb(255, 255, 255); border-radius: 50%;"></div></div></div><div data-processed="true"><div class="SrjfCd" data-processed="true" style="color: rgb(31, 31, 31); font-size: 12px; line-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">Fireship</div><div class="Pcl3Vd" data-processed="true" style="color: rgb(31, 31, 31); letter-spacing: 0px; font-size: 11px; line-height: 13px;">YouTube • 27 Jun 2022</div></div></div>](https://www.youtube.com/watch?v=gdlTFPebzAU)</div></div></div></div></div></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&pXoq0d_10|npT2md" jscontroller="KHhJQ" jsuid="pXoq0d_10" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-core-concepts%3A" jscontroller="a7qCn" jsuid="pXoq0d_11" role="heading" style="color: rgb(0, 29, 53); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 20px; line-height: 28px; margin: 20px 0px 10px; font-weight: 600; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Core Concepts:<span class="txxDge notranslate" data-processed="true" data-wiz-uids="pXoq0d_12,pXoq0d_13,pXoq0d_14" style="visibility: hidden;"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"><button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="40a59637-601e-4058-88d6-2c381aa1f2cd" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQye0OegQIAxAA" data-wiz-attrbind="disabled=pXoq0d_12/C5gNJc;class=pXoq0d_12/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div>- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**[Isolation](https://www.google.com/search?q=Isolation&sca_esv=8ab2282fee241d3c&sxsrf=AE3TifPSVfYbyCUp3jW67zu5Rmfn0cxecA%3A1765433073999&ei=8V46afnXPIzRg8UPwdPPwA8&ved=2ahUKEwidha_d7rSRAxXzzjgGHSliKisQgK4QegQIBRAB&uact=5&oq=storybook+tool++bsics&gs_lp=Egxnd3Mtd2l6LXNlcnAiFXN0b3J5Ym9vayB0b29sICBic2ljczIHECEYoAEYCjIHECEYoAEYCjIFECEYnwVI7B5Q3wtY9BtwAXgBkAEAmAGaAqABwQuqAQUwLjMuNLgBA8gBAPgBAZgCCKACtwzCAgoQABiwAxjWBBhHwgIGEAAYFhgewgIFECEYoAGYAwCIBgGQBgiSBwcxLjMuMy4xoAftGrIHBzAuMy4zLjG4B6oMwgcHMi01LjIuMcgHRoAIAA&sclient=gws-wiz-serp&mstk=AUtExfCJFd01ZrJ1TunK3o6YLF5fwWOkW19cNKst9C_zP3vrwcxuG4uoTKNFj0x9vkRWD6A-NE4Vwlpd66S10E46LtNRuXJzT3uwUGhspzfO2Ju5xUUfNoLzM2qjCzHwlGVHKtDiJ9QGlK5uA6cjH24vtNEe6zQIjP3fDQw9XwAHgzcYV-Wxr5oLeDtvZfYtS3oarFSB5m91qh9ANSAhwc1_JlmAywDQgtoKgbEd3foWwVj62ZKPx8-p2GmIdX2lm5nHnp-mNZiOGY2N2Xopg-POfcE1&csui=3):** Develop components without app complexities (data, routing) in a clean environment.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**[Stories](https://www.google.com/search?q=Stories&sca_esv=8ab2282fee241d3c&sxsrf=AE3TifPSVfYbyCUp3jW67zu5Rmfn0cxecA%3A1765433073999&ei=8V46afnXPIzRg8UPwdPPwA8&ved=2ahUKEwidha_d7rSRAxXzzjgGHSliKisQgK4QegQIBRAD&uact=5&oq=storybook+tool++bsics&gs_lp=Egxnd3Mtd2l6LXNlcnAiFXN0b3J5Ym9vayB0b29sICBic2ljczIHECEYoAEYCjIHECEYoAEYCjIFECEYnwVI7B5Q3wtY9BtwAXgBkAEAmAGaAqABwQuqAQUwLjMuNLgBA8gBAPgBAZgCCKACtwzCAgoQABiwAxjWBBhHwgIGEAAYFhgewgIFECEYoAGYAwCIBgGQBgiSBwcxLjMuMy4xoAftGrIHBzAuMy4zLjG4B6oMwgcHMi01LjIuMcgHRoAIAA&sclient=gws-wiz-serp&mstk=AUtExfCJFd01ZrJ1TunK3o6YLF5fwWOkW19cNKst9C_zP3vrwcxuG4uoTKNFj0x9vkRWD6A-NE4Vwlpd66S10E46LtNRuXJzT3uwUGhspzfO2Ju5xUUfNoLzM2qjCzHwlGVHKtDiJ9QGlK5uA6cjH24vtNEe6zQIjP3fDQw9XwAHgzcYV-Wxr5oLeDtvZfYtS3oarFSB5m91qh9ANSAhwc1_JlmAywDQgtoKgbEd3foWwVj62ZKPx8-p2GmIdX2lm5nHnp-mNZiOGY2N2Xopg-POfcE1&csui=3):** Code snippets defining different UI states (e.g., a button in primary, secondary, disabled states) for a component.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**[Sandbox](https://www.google.com/search?q=Sandbox&sca_esv=8ab2282fee241d3c&sxsrf=AE3TifPSVfYbyCUp3jW67zu5Rmfn0cxecA%3A1765433073999&ei=8V46afnXPIzRg8UPwdPPwA8&ved=2ahUKEwidha_d7rSRAxXzzjgGHSliKisQgK4QegQIBRAF&uact=5&oq=storybook+tool++bsics&gs_lp=Egxnd3Mtd2l6LXNlcnAiFXN0b3J5Ym9vayB0b29sICBic2ljczIHECEYoAEYCjIHECEYoAEYCjIFECEYnwVI7B5Q3wtY9BtwAXgBkAEAmAGaAqABwQuqAQUwLjMuNLgBA8gBAPgBAZgCCKACtwzCAgoQABiwAxjWBBhHwgIGEAAYFhgewgIFECEYoAGYAwCIBgGQBgiSBwcxLjMuMy4xoAftGrIHBzAuMy4zLjG4B6oMwgcHMi01LjIuMcgHRoAIAA&sclient=gws-wiz-serp&mstk=AUtExfCJFd01ZrJ1TunK3o6YLF5fwWOkW19cNKst9C_zP3vrwcxuG4uoTKNFj0x9vkRWD6A-NE4Vwlpd66S10E46LtNRuXJzT3uwUGhspzfO2Ju5xUUfNoLzM2qjCzHwlGVHKtDiJ9QGlK5uA6cjH24vtNEe6zQIjP3fDQw9XwAHgzcYV-Wxr5oLeDtvZfYtS3oarFSB5m91qh9ANSAhwc1_JlmAywDQgtoKgbEd3foWwVj62ZKPx8-p2GmIdX2lm5nHnp-mNZiOGY2N2Xopg-POfcE1&csui=3):** The Storybook UI where components are rendered and interacted with.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**[Add-ons](https://www.google.com/search?q=Add-ons&sca_esv=8ab2282fee241d3c&sxsrf=AE3TifPSVfYbyCUp3jW67zu5Rmfn0cxecA%3A1765433073999&ei=8V46afnXPIzRg8UPwdPPwA8&ved=2ahUKEwidha_d7rSRAxXzzjgGHSliKisQgK4QegQIBRAH&uact=5&oq=storybook+tool++bsics&gs_lp=Egxnd3Mtd2l6LXNlcnAiFXN0b3J5Ym9vayB0b29sICBic2ljczIHECEYoAEYCjIHECEYoAEYCjIFECEYnwVI7B5Q3wtY9BtwAXgBkAEAmAGaAqABwQuqAQUwLjMuNLgBA8gBAPgBAZgCCKACtwzCAgoQABiwAxjWBBhHwgIGEAAYFhgewgIFECEYoAGYAwCIBgGQBgiSBwcxLjMuMy4xoAftGrIHBzAuMy4zLjG4B6oMwgcHMi01LjIuMcgHRoAIAA&sclient=gws-wiz-serp&mstk=AUtExfCJFd01ZrJ1TunK3o6YLF5fwWOkW19cNKst9C_zP3vrwcxuG4uoTKNFj0x9vkRWD6A-NE4Vwlpd66S10E46LtNRuXJzT3uwUGhspzfO2Ju5xUUfNoLzM2qjCzHwlGVHKtDiJ9QGlK5uA6cjH24vtNEe6zQIjP3fDQw9XwAHgzcYV-Wxr5oLeDtvZfYtS3oarFSB5m91qh9ANSAhwc1_JlmAywDQgtoKgbEd3foWwVj62ZKPx8-p2GmIdX2lm5nHnp-mNZiOGY2N2Xopg-POfcE1&csui=3):** Plugins that extend functionality, like controls for props, accessibility checks, or viewport resizing.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="pXoq0d_2w,pXoq0d_2x,pXoq0d_2y"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="b5ceeae6-f243-4e29-a4aa-6a71b219e087" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQye0OegQIBRAI" data-wiz-attrbind="disabled=pXoq0d_2w/C5gNJc;class=pXoq0d_2w/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--1" jsaction="rcuQ6b:&pXoq0d_38|npT2md" jscontroller="KHhJQ" jsuid="pXoq0d_38" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-basic-workflow%3A" jscontroller="a7qCn" jsuid="pXoq0d_39" role="heading" style="color: rgb(0, 29, 53); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 20px; line-height: 28px; margin: 20px 0px 10px; font-weight: 600; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Basic Workflow:<span class="txxDge notranslate" data-processed="true" data-wiz-uids="pXoq0d_3a,pXoq0d_3b,pXoq0d_3c" style="visibility: hidden;"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"><button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="79e4ae3f-83a7-4569-944b-4389eb984bb5" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQye0OegQIBhAA" data-wiz-attrbind="disabled=pXoq0d_3a/C5gNJc;class=pXoq0d_3a/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div>1. <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Install:** Add Storybook to your project (`npx sb init`).</span>
2. <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Create Stories:** In your component's `stories` folder, `export` your component and define stories (e.g., `export const Primary = () => <Button primary />;`).</span>
3. <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Run:** Start the development server with `npm run storybook` (or `yarn storybook`).</span>
4. <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Develop &amp; Test:**</span>
    - <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">Use the sidebar to select stories.</span>
    - <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">Interact with components in the sandbox.</span>
    - <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">Use the Controls panel to change props dynamically.</span>
    - <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">Add testing add-ons for quality assurance.</span>
5. <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Document:** Storybook automatically generates documentation from your stories, making them shareable and reusable.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="pXoq0d_48,pXoq0d_49,pXoq0d_4a"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="285a195e-222a-4ae6-b2c3-0eb28b1db991" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQye0OegQIBxAJ" data-wiz-attrbind="disabled=pXoq0d_48/C5gNJc;class=pXoq0d_48/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span>

<div class="Y3BBE" data-hveid="CAgQAA" data-processed="true" data-sfc-cp="" id="bkmrk-this-video-demonstra" jsaction="rcuQ6b:&pXoq0d_4i|npT2md" jscontroller="zcfIf" jsuid="pXoq0d_4i" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 10px 0px 20px; color: rgb(10, 10, 10); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">This video demonstrates how to set up and use Storybook: <div class="" data-processed="true" data-wiz-uids="pXoq0d_4k,pXoq0d_4l" jscontroller="uDeH3" jsuid="pXoq0d_4j"><div data-hveid="CAgQAQ" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQ-bUQegQICBAB"><div data-processed="true"><div class="Q2WBBe" data-processed="true" jsuid="pXoq0d_4l" style="container-type: inline-size; display: flex; flex-direction: column; background-color: rgb(243, 245, 246); margin-top: 12px; border-radius: 16px;"><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQypYSegQICBAC" jsuid="pXoq0d_4k" style="overflow: hidden; position: relative; border-radius: 16px 16px 0px 0px; width: 631.987px; height: 353.906px; outline: 0px;" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="pXoq0d_4n" jsaction="rcuQ6b:&pXoq0d_4m|npT2md" jscallback="gfNXHe:&pXoq0d_4j:U8wGUb" jscontroller="wMmv4c" jsuid="pXoq0d_4m" style="width: 631.987px; height: 353.906px;"><div class="nrdPJf" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQtbEQegQICBAD" jsaction="click:&pXoq0d_4m|T2P31d" jsuid="pXoq0d_4n" role="button" style="cursor: pointer; width: 631.987px; height: 353.906px; outline: 0px;" tabindex="0"><div class="n7j80c YkW4Kb" data-processed="true" jscontroller="ItMuwb" jsuid="pXoq0d_4o" style="border-radius: 100px; bottom: 12px; height: 4px; left: 12px; position: absolute; width: calc(100% - 24px); z-index: 2; --segment-bar-offset: 12px;"><div class="llCCib" data-processed="true" style="transform: translateX(-50%); width: fit-content; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); opacity: 0.85; border-radius: 100px; color: rgb(31, 31, 31); display: flex; flex-direction: row; font-size: 12px; gap: 4px; line-height: 1.33; padding: 2px 8px; position: absolute; top: -27px; white-space: nowrap; left: 60.7875px;"><svg fill="currentColor" height="12" viewbox="0 0 12 12" width="12" xmlns="http://www.w3.org/2000/svg"><path d="M3.5 2.7611V9.2386C3.5 9.77772 4.10085 10.0993 4.54942 9.80023L9.40755 6.56148C9.80832 6.2943 9.80832 5.70539 9.40755 5.43821L4.54942 2.19946C4.10085 1.90041 3.5 2.22198 3.5 2.7611Z"></path></svg><span data-processed="true">59s</span></div><div class="s3ITrd" data-processed="true" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); opacity: 0.85; display: flex; height: 3.99375px; justify-content: center; position: absolute; z-index: 1; left: 24.3187px; width: 72.9562px;"><div class="PoLW7d" data-processed="true" style="position: absolute; border-left: 3.5px solid transparent; border-right: 3.5px solid transparent; border-top: 2.4px solid rgb(255, 255, 255); top: -7px;">  
</div></div></div><div class="dumoDb YkW4Kb" data-processed="true" style="z-index: 2; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.6); border-radius: 100px; cursor: pointer; position: absolute; right: 14px; top: 12px;"><div class="CaQWce" data-processed="true" jscontroller="sRLmTc" jsuid="pXoq0d_4p" style="align-items: center; color: rgb(255, 255, 255); display: flex; height: 20px; justify-content: center; transform: rotate(45deg); width: 20px;"><svg fill="currentColor" height="18px" viewbox="0 -960 960 960" width="18px" xmlns="http://www.w3.org/2000/svg"><path d="M480-120 300-300l58-58 122 122 122-122 58 58-180 180ZM358-598l-58-58 180-180 180 180-58 58-122-122-122 122Z" fill="currentColor"></path></svg></div></div></div></div></div><div data-processed="true">[<div class="RhEuY" data-processed="true" style="display: flex; padding: 16px 12px 12px; gap: 8px; align-items: center;"><div class="SWvopd" data-processed="true" jscontroller="aNJZAb" jsuid="pXoq0d_4q" style="height: fit-content; width: fit-content; margin-bottom: 2px; position: relative;"><div class="Lki2rc" data-processed="true" style="width: 20px; height: 20px; line-height: 20px;"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="pXoq0d_4r" style="width: 19.9875px; height: 19.9875px; line-height: 16px; display: flex; flex-shrink: 0; align-items: center; justify-content: center; overflow: hidden; background-color: rgb(255, 255, 255); border-radius: 50%;"></div></div><div class="JccCTc xG6cCf" data-processed="true" style="position: absolute; bottom: -4px; right: -4px; border-radius: 50%; line-height: 10px; padding: 2px; background-color: rgb(255, 255, 255); width: 10px; height: 10px;"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="pXoq0d_4s" style="width: 9.99375px; height: 9.99375px; line-height: 16px; display: flex; flex-shrink: 0; align-items: center; justify-content: center; overflow: hidden; background-color: rgb(255, 255, 255); border-radius: 50%;"></div></div></div><div data-processed="true"><div class="SrjfCd" data-processed="true" style="color: rgb(31, 31, 31); font-size: 12px; line-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">Bayan Bennett</div><div class="Pcl3Vd" data-processed="true" style="color: rgb(31, 31, 31); letter-spacing: 0px; font-size: 11px; line-height: 13px;">YouTube • 30 Mar 2022</div></div></div>](https://www.youtube.com/watch?v=qwIzvFNqJwg&t=16)</div></div></div></div></div></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--2" jsaction="rcuQ6b:&pXoq0d_4t|npT2md" jscontroller="KHhJQ" jsuid="pXoq0d_4t" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-key-benefits%3A" jscontroller="a7qCn" jsuid="pXoq0d_4u" role="heading" style="color: rgb(0, 29, 53); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 20px; line-height: 28px; margin: 20px 0px 10px; font-weight: 600; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Key Benefits:<span class="txxDge notranslate" data-processed="true" data-wiz-uids="pXoq0d_4v,pXoq0d_4w,pXoq0d_4x" style="visibility: hidden;"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"><button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="abd5a26d-6e27-467c-8fc6-0e43d52292ea" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQye0OegQICRAA" data-wiz-attrbind="disabled=pXoq0d_4v/C5gNJc;class=pXoq0d_4v/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div>- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Faster Development:** Focus on one component at a time.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Consistency:** Build a shared library of components.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Collaboration:** Designers, developers, and stakeholders can review UIs easily.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Testing:** Integrated testing for UI bugs.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="pXoq0d_5b,pXoq0d_5c,pXoq0d_5d"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="ecbd575d-30c4-42ce-b3e7-d3b86a86aa37" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQye0OegQIChAE" data-wiz-attrbind="disabled=pXoq0d_5b/C5gNJc;class=pXoq0d_5b/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span>

<div class="Y3BBE" data-hveid="CAwQAA" data-processed="true" data-sfc-cp="" id="bkmrk-this-video-explains-" jsaction="rcuQ6b:&pXoq0d_9p|npT2md" jscontroller="zcfIf" jsuid="pXoq0d_9p" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 10px 0px 20px; color: rgb(10, 10, 10); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">This video explains the core concepts of Storybook: <div class="" data-processed="true" data-wiz-uids="pXoq0d_9r,pXoq0d_9s" jscontroller="uDeH3" jsuid="pXoq0d_9q"><div data-hveid="CAwQAQ" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQ-bUQegQIDBAB"><div data-processed="true"><div class="Q2WBBe" data-processed="true" jsuid="pXoq0d_9s" style="container-type: inline-size; display: flex; flex-direction: column; background-color: rgb(243, 245, 246); margin-top: 12px; border-radius: 16px;"><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQypYSegQIDBAC" jsuid="pXoq0d_9r" style="overflow: hidden; position: relative; border-radius: 16px 16px 0px 0px; width: 631.987px; height: 353.906px; outline: 0px;" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="pXoq0d_9u" jsaction="rcuQ6b:&pXoq0d_9t|npT2md" jscallback="gfNXHe:&pXoq0d_9q:U8wGUb" jscontroller="wMmv4c" jsuid="pXoq0d_9t" style="width: 631.987px; height: 353.906px;"><div class="nrdPJf" data-processed="true" data-ved="2ahUKEwidha_d7rSRAxXzzjgGHSliKisQtbEQegQIDBAD" jsaction="click:&pXoq0d_9t|T2P31d" jsuid="pXoq0d_9u" role="button" style="cursor: pointer; width: 631.987px; height: 353.906px; outline: 0px;" tabindex="0"><div class="n7j80c YkW4Kb" data-processed="true" jscontroller="ItMuwb" jsuid="pXoq0d_9v" style="border-radius: 100px; bottom: 12px; height: 4px; left: 12px; position: absolute; width: calc(100% - 24px); z-index: 2; --segment-bar-offset: 12px;"><div class="llCCib" data-processed="true" style="transform: translateX(-50%); width: fit-content; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); opacity: 0.85; border-radius: 100px; color: rgb(31, 31, 31); display: flex; flex-direction: row; font-size: 12px; gap: 4px; line-height: 1.33; padding: 2px 8px; position: absolute; top: -27px; white-space: nowrap; left: 39.5062px;"><svg fill="currentColor" height="12" viewbox="0 0 12 12" width="12" xmlns="http://www.w3.org/2000/svg"><path d="M3.5 2.7611V9.2386C3.5 9.77772 4.10085 10.0993 4.54942 9.80023L9.40755 6.56148C9.80832 6.2943 9.80832 5.70539 9.40755 5.43821L4.54942 2.19946C4.10085 1.90041 3.5 2.22198 3.5 2.7611Z"></path></svg><span data-processed="true">1m</span></div><div class="s3ITrd" data-processed="true" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); opacity: 0.85; display: flex; height: 3.99375px; justify-content: center; position: absolute; z-index: 1; left: 30.3937px; width: 18.225px;"><div class="PoLW7d" data-processed="true" style="position: absolute; border-left: 3.5px solid transparent; border-right: 3.5px solid transparent; border-top: 2.4px solid rgb(255, 255, 255); top: -7px;">  
</div></div></div><div class="dumoDb YkW4Kb" data-processed="true" style="z-index: 2; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.6); border-radius: 100px; cursor: pointer; position: absolute; right: 14px; top: 12px;"><div class="CaQWce" data-processed="true" jscontroller="sRLmTc" jsuid="pXoq0d_9w" style="align-items: center; color: rgb(255, 255, 255); display: flex; height: 20px; justify-content: center; transform: rotate(45deg); width: 20px;"><svg fill="currentColor" height="18px" viewbox="0 -960 960 960" width="18px" xmlns="http://www.w3.org/2000/svg"><path d="M480-120 300-300l58-58 122 122 122-122 58 58-180 180ZM358-598l-58-58 180-180 180 180-58 58-122-122-122 122Z" fill="currentColor"></path></svg></div></div></div></div></div><div data-processed="true">[<div class="RhEuY" data-processed="true" style="display: flex; padding: 16px 12px 12px; gap: 8px; align-items: center;"><div class="SWvopd" data-processed="true" jscontroller="aNJZAb" jsuid="pXoq0d_9x" style="height: fit-content; width: fit-content; margin-bottom: 2px; position: relative;"><div class="Lki2rc" data-processed="true" style="width: 20px; height: 20px; line-height: 20px;"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="pXoq0d_9y" style="width: 19.9875px; height: 19.9875px; line-height: 16px; display: flex; flex-shrink: 0; align-items: center; justify-content: center; overflow: hidden; background-color: rgb(255, 255, 255); border-radius: 50%;"></div></div><div class="JccCTc xG6cCf" data-processed="true" style="position: absolute; bottom: -4px; right: -4px; border-radius: 50%; line-height: 10px; padding: 2px; background-color: rgb(255, 255, 255); width: 10px; height: 10px;"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="pXoq0d_9z" style="width: 9.99375px; height: 9.99375px; line-height: 16px; display: flex; flex-shrink: 0; align-items: center; justify-content: center; overflow: hidden; background-color: rgb(255, 255, 255); border-radius: 50%;"></div></div></div><div data-processed="true"><div class="SrjfCd" data-processed="true" style="color: rgb(31, 31, 31); font-size: 12px; line-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">Cosden Solutions</div><div class="Pcl3Vd" data-processed="true" style="color: rgb(31, 31, 31); letter-spacing: 0px; font-size: 11px; line-height: 13px;">YouTube • 16 Jul 2024</div></div></div>](https://www.youtube.com/watch?v=dwtmz5PHWDg&t=118)</div></div></div></div></div></div>

# Angular vs React

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk-angular%C2%A0is-a-compreh" jsaction="rcuQ6b:&NdqIQe_7|npT2md" jscontroller="zcfIf" jsuid="NdqIQe_7" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 0px 0px 20px; color: rgb(10, 10, 10); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><mark class="HxTRcb" data-processed="true" style="color: rgb(0, 29, 53); border-radius: 4px; background: linear-gradient(90deg, rgb(211, 227, 253) 50%, rgba(0, 0, 0, 0) 50%) 75% 0px / 200% 100% no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); padding: 0px 2px; font-weight: 500; animation: 0.75s cubic-bezier(0.05, 0.7, 0.1, 1) 0.25s 1 normal forwards running highlight-animation;">**<span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;"><span data-processed="true" data-sfc-cp="">[Angular](https://angular.dev/)</span> is a comprehensive, opinionated framework ideal for large, enterprise-scale projects, while React is a flexible, lightweight library focused solely on building user interfaces</span>**</mark>. The best choice depends on project size, team expertise, and required flexibility.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="NdqIQe_d,NdqIQe_e,NdqIQe_f"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="1e1adf2c-1796-4da8-a880-b13a97c6592b" data-processed="true" data-ved="2ahUKEwj3tYa27LSRAxWJHjQIHU5UCrEQye0OegQIARAD" data-wiz-attrbind="disabled=NdqIQe_d/C5gNJc;class=NdqIQe_d/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&NdqIQe_i|npT2md" jscontroller="KHhJQ" jsuid="NdqIQe_i" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-core-distinctions" jscontroller="a7qCn" jsuid="NdqIQe_j" role="heading" style="color: rgb(0, 29, 53); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 20px; line-height: 28px; margin: 20px 0px 10px; font-weight: 600; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Core Distinctions<span class="txxDge notranslate" data-processed="true" data-wiz-uids="NdqIQe_k,NdqIQe_l,NdqIQe_m" style="visibility: hidden;"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"><button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="94d1ad24-e8a0-475e-b901-aa8188605f49" data-processed="true" data-ved="2ahUKEwj3tYa27LSRAxWJHjQIHU5UCrEQye0OegQIAhAA" data-wiz-attrbind="disabled=NdqIQe_k/C5gNJc;class=NdqIQe_k/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--1" jsaction="rcuQ6b:&NdqIQe_n|npT2md" jscontroller="KHhJQ" jsuid="NdqIQe_n" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div class="Fv6NCb" data-processed="true" data-sfc-cp="" data-ved="2ahUKEwj3tYa27LSRAxWJHjQIHU5UCrEQ-q4QegQIAxAA" data-wiz-uids="NdqIQe_o" id="bkmrk-feature%C2%A0-angular-rea" jsaction="rcuQ6b:&NdqIQe_o|npT2md" jscontroller="kbUand" jsuid="NdqIQe_o" style="overflow-x: auto; width: auto; box-sizing: border-box; scrollbar-width: none; margin: 10px 0px 20px; color: rgb(10, 10, 10); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><table class="NRefec" data-animation-nesting="" data-processed="true" style="border: none; border-collapse: collapse; table-layout: auto; width: 631.987px;"><tbody data-processed="true"><tr class="cZCYO" data-processed="true" data-sfc-cp=""><th class="iry6k" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 8px 16px 8px 0px; text-align: left; font-weight: bold; border-block-end: 1.2px solid rgb(169, 172, 170); padding-block: 0px 12px; padding-inline-end: 10px;">Feature<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="NdqIQe_r,NdqIQe_s,NdqIQe_t"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="d02f6d4c-9747-4ab9-952a-8e4af77396ad" data-processed="true" data-ved="2ahUKEwj3tYa27LSRAxWJHjQIHU5UCrEQye0OegQIAxAB" data-wiz-attrbind="disabled=NdqIQe_r/C5gNJc;class=NdqIQe_r/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></th><th class="iry6k" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 8px 16px 8px 0px; text-align: left; font-weight: bold; border-block-end: 1.2px solid rgb(169, 172, 170); padding-block: 0px 12px; padding-inline: 10px;">Angular</th><th class="iry6k" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 8px 0px; text-align: left; font-weight: bold; border-block-end: 1.2px solid rgb(169, 172, 170); padding-block: 0px 12px; padding-inline-start: 10px;">React</th></tr><tr class="cZCYO" data-processed="true" data-sfc-cp=""><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline-end: 10px;">**Type**</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline: 10px;">Full-fledged framework (MVC/MVVM)</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline-start: 10px;">JavaScript library (view layer only)</td></tr><tr class="cZCYO" data-processed="true" data-sfc-cp=""><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline-end: 10px;">**Language**</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline: 10px;">TypeScript (mandatory)</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline-start: 10px;">JavaScript (JSX), TypeScript is optional</td></tr><tr class="cZCYO" data-processed="true" data-sfc-cp=""><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline-end: 10px;">**Data Binding**</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline: 10px;">Two-way (automatic sync)</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline-start: 10px;">One-way (unidirectional flow)</td></tr><tr class="cZCYO" data-processed="true" data-sfc-cp=""><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline-end: 10px;">**DOM**</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline: 10px;">Real DOM (optimized with techniques like Ivy)</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline-start: 10px;">Virtual DOM (faster UI updates)</td></tr><tr class="cZCYO" data-processed="true" data-sfc-cp=""><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline-end: 10px;">**Built-in Features**</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline: 10px;">Comprehensive (routing, form handling, HTTP client, testing tools, CLI)</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline-start: 10px;">Minimal (requires third-party libraries for most features like routing or state management)</td></tr><tr class="cZCYO" data-processed="true" data-sfc-cp=""><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline-end: 10px;">**Learning Curve**</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline: 10px;">Steeper (requires understanding TypeScript, dependency injection, etc.)</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="border-bottom: 1.2px solid rgb(210, 210, 210); min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 0px; border-block-end: 1.2px solid rgb(169, 172, 170); font-weight: 400; padding-inline-start: 10px;">Moderate (easier to start for JavaScript developers)</td></tr><tr class="cZCYO" data-processed="true" data-sfc-cp=""><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 0px solid rgb(169, 172, 170); font-weight: 400; padding-inline-end: 10px; border-bottom: none;">**Backing**</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 16px 12px 0px; border-block-end: 0px solid rgb(169, 172, 170); font-weight: 400; border-bottom: none; padding-inline: 10px;">Google</td><td class="cOeeGf" colspan="undefined" data-processed="true" data-sfc-cp="" style="min-width: 4em; vertical-align: top; color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; line-height: 22px; padding: 12px 0px; border-block-end: 0px solid rgb(169, 172, 170); font-weight: 400; padding-inline-start: 10px; border-bottom: none;">Meta (Facebook)</td></tr></tbody></table>

</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--2" jsaction="rcuQ6b:&NdqIQe_21|npT2md" jscontroller="KHhJQ" jsuid="NdqIQe_21" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-when-to-choose-react" jscontroller="a7qCn" jsuid="NdqIQe_22" role="heading" style="color: rgb(0, 29, 53); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 20px; line-height: 28px; margin: 20px 0px 10px; font-weight: 600; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">When to Choose React<span class="txxDge notranslate" data-processed="true" data-wiz-uids="NdqIQe_23,NdqIQe_24,NdqIQe_25" style="visibility: hidden;"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"><button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="3ccc7d97-e871-4da4-a6f2-3f51e0069b7c" data-processed="true" data-ved="2ahUKEwj3tYa27LSRAxWJHjQIHU5UCrEQye0OegQIBBAA" data-wiz-attrbind="disabled=NdqIQe_23/C5gNJc;class=NdqIQe_23/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div>- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Rapid Development &amp; Flexibility:** React's minimalist nature allows for quick iterations and a high degree of control over your technology stack.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Dynamic UIs &amp; Performance:** Ideal for applications requiring frequent UI updates, such as social media feeds or dashboards, due to its efficient virtual DOM implementation.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Small to Medium Projects &amp; Startups:** Its gentler learning curve and flexibility make it suitable for smaller teams and projects where a quick launch is a priority.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Mobile Development:** It offers strong support for native mobile app development via React Native.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="NdqIQe_2k,NdqIQe_2l,NdqIQe_2m"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="0fd90539-4609-437c-9af5-8fcea8ef0514" data-processed="true" data-ved="2ahUKEwj3tYa27LSRAxWJHjQIHU5UCrEQye0OegQIBRAE" data-wiz-attrbind="disabled=NdqIQe_2k/C5gNJc;class=NdqIQe_2k/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--3" jsaction="rcuQ6b:&NdqIQe_2q|npT2md" jscontroller="KHhJQ" jsuid="NdqIQe_2q" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-when-to-choose-angul" jscontroller="a7qCn" jsuid="NdqIQe_2r" role="heading" style="color: rgb(0, 29, 53); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 20px; line-height: 28px; margin: 20px 0px 10px; font-weight: 600; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">When to Choose Angular<span class="txxDge notranslate" data-processed="true" data-wiz-uids="NdqIQe_2s,NdqIQe_2t,NdqIQe_2u" style="visibility: hidden;"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"><button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="c34e52a1-6097-4da7-abc7-0938561f2433" data-processed="true" data-ved="2ahUKEwj3tYa27LSRAxWJHjQIHU5UCrEQye0OegQIBhAA" data-wiz-attrbind="disabled=NdqIQe_2s/C5gNJc;class=NdqIQe_2s/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div>- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Large-Scale Enterprise Applications:** Angular's opinionated and structured architecture provides consistency and maintainability, which is crucial for complex, long-term projects with large teams (e.g., ERP systems, banking platforms).</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Complex Forms &amp; Data-Heavy Apps:** Its powerful built-in form handling and two-way data binding streamline data-intensive interactions.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Teams Familiar with TypeScript/OOP:** If your team has experience with TypeScript or object-oriented languages like Java or C#, Angular's structure will feel more natural.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Integrated Solutions:** If you prefer an all-in-one framework that provides most necessary tools out of the box, reducing "decision fatigue" on which external libraries to use, Angular is a strong choice.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="NdqIQe_38,NdqIQe_39,NdqIQe_3a"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"> </span></span>

# Efficient State Management (Redux, Recoil, Context API, Zustand, etc.)

<div class="WaaZC" id="bkmrk-fficient-state-manag" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc" data-hveid="CAUQAQ" data-ved="2ahUKEwjikfuA4YORAxVFS2wGHffNHfkQo_EKegQIBRAB" style="margin: 0px 0px 10px;"><span data-huuid="8250654214376267930">fficient state management in applications, particularly in front-end frameworks like React, involves choosing the right tools and strategies to handle data flow, updates, and synchronization across components while optimizing performance. </span><span data-huuid="8250654214376271693">Several popular solutions exist, each with its strengths and trade-offs:</span></div></div></div><div class="WaaZC" id="bkmrk-1.-redux%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc uP58nb" data-hveid="CAIQAQ" data-ved="2ahUKEwjikfuA4YORAxVFS2wGHffNHfkQo_EKegQIAhAB" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="8250654214376271027"><span aria-level="2" role="heading">1. Redux:</span></span></div></div></div><div class="WaaZC" id="bkmrk-strengths%3A%C2%A0-centrali" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 0px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="8250654214376270028">**Strengths:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="8250654214376269695">Centralized, predictable state with strict conventions (actions, reducers, store). </span><span data-huuid="8250654214376269362">Excellent for large, complex applications requiring robust debugging tools, middleware support, and a clear data flow.</span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="8250654214376268696">**Considerations:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="8250654214376268363">Can involve more boilerplate code and a steeper learning curve, potentially being overkill for smaller projects.</span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-2.-context-api-%28reac" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc uP58nb" data-hveid="CBQQAQ" data-ved="2ahUKEwjikfuA4YORAxVFS2wGHffNHfkQo_EKegQIFBAB" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="13145011493932165177"><span aria-level="2" role="heading">2. Context API (React's Built-in):</span><span class="pjBG2e" data-cid="e64e60e1-40a6-47a5-826b-1c418d729c32"><span class="UV3uM" style="white-space: nowrap;"> </span></span></span><div class="NPrrbc" data-cid="e64e60e1-40a6-47a5-826b-1c418d729c32" data-uuids="13145011493932165177,13145011493932167096,13145011493932165005,13145011493932167010,13145011493932166924,13145011493932164833" style="margin-inline-end: 6px; vertical-align: middle; display: inline-flex;"><div aria-label="View related links" class="BMebGe btku5b LwdV0e FR7ZSc OJeuxf" data-hveid="CBMQAQ" data-ved="2ahUKEwjikfuA4YORAxVFS2wGHffNHfkQ3fYKegQIExAB" jsaction="KjsqPd" jsname="HtgYJd" role="button" style="display: inline-flex !important; vertical-align: middle; cursor: pointer; outline: 0px; -webkit-tap-highlight-color: transparent; color: rgb(28, 65, 154);" tabindex="0"><div class="niO4u" style="display: flex; justify-content: center; position: relative; align-items: center; width: 28px; z-index: 0; box-sizing: border-box; border-radius: 9999px; padding: 0px; border: 1px solid transparent; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(229, 237, 255) !important; height: 20px; margin: 0px auto; min-height: 20px;"><span class="TwMgNb Hkv2Pe" style="color: rgb(31, 31, 31) !important; background: unset !important; display: flex; align-items: center;"><span class="iPjmzb Sorfoc gNGSDf" style="display: flex; height: unset; rotate: 135deg;"><span class="z1asCe Sb7k4e" style="display: inline-block; fill: currentcolor; height: 18px; line-height: 18px; position: relative; width: 18px;"><svg aria-hidden="true" focusable="false" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></span></span></div></div></div></div></div></div><div class="WaaZC" id="bkmrk-strengths%3A%C2%A0-simple%2C-" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 0px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="13145011493932167096">**Strengths:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="13145011493932165005">Simple, built-in solution for managing global state like themes or user authentication preferences without prop drilling. </span><span data-huuid="13145011493932167010">Less boilerplate than Redux.</span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="13145011493932166924">**Considerations:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="13145011493932164833">Can lead to performance issues with frequent updates if not optimized carefully, as consumers re-render whenever the context value changes.</span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-3.-recoil%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc uP58nb" data-hveid="CCIQAQ" data-ved="2ahUKEwjikfuA4YORAxVFS2wGHffNHfkQo_EKegQIIhAB" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="8250654214376271793"><span aria-level="2" role="heading">3. Recoil:</span></span></div></div></div><div class="WaaZC" id="bkmrk-strengths%3A%C2%A0-modern%2C-" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 0px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="8250654214376270794">**Strengths:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="8250654214376270461">Modern, lightweight, and atom-based, aligning well with React's component-based architecture. </span><span data-huuid="8250654214376270128">Offers granular updates, reducing unnecessary re-renders in complex applications.</span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="8250654214376269462">**Considerations:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="8250654214376269129">Newer library with a smaller ecosystem compared to Redux, though gaining popularity.</span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-4.-zustand%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc uP58nb" data-hveid="CC4QAQ" data-ved="2ahUKEwjikfuA4YORAxVFS2wGHffNHfkQo_EKegQILhAB" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="9764199558440567714"><span aria-level="2" role="heading">4. Zustand:</span></span></div></div></div><div class="WaaZC" id="bkmrk-strengths%3A%C2%A0-minimali" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 0px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="9764199558440569497">**Strengths:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="9764199558440568726">Minimalist, fast, and scalable, leveraging React Hooks for a straightforward API. </span><span data-huuid="9764199558440567955">Requires minimal boilerplate and no provider wrapping, making it easy to integrate.</span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="9764199558440570509">**Considerations:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="9764199558440569738">Less opinionated than Redux, potentially requiring more team conventions for large projects.</span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-choosing-the-right-s" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CDwQAQ" data-ved="2ahUKEwjikfuA4YORAxVFS2wGHffNHfkQo_EKegQIPBAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="12465421110250947710">Choosing the Right Solution:</span></div></div></div><div class="WaaZC" id="bkmrk-the-optimal-choice-d" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc uP58nb" data-hveid="CDsQAQ" data-ved="2ahUKEwjikfuA4YORAxVFS2wGHffNHfkQo_EKegQIOxAB" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="12465421110250948556"><span aria-level="2" role="heading">The optimal choice depends on the application's specific needs:</span></span></div></div></div><div class="WaaZC" id="bkmrk-small-to-medium-size" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <span data-huuid="12465421110250947777">**Small to Medium-sized Applications:** </span><span data-huuid="12465421110250950248">Context API or Zustand can be efficient choices due to their simplicity and minimal overhead.</span>
- <span data-huuid="12465421110250946998">**Large-scale Applications with Complex State:** </span><span data-huuid="12465421110250949469">Redux offers robust features for managing intricate state logic and debugging.</span>
- <span data-huuid="12465421110250950315">**Applications Requiring Fine-grained Updates and Performance:** </span><span data-huuid="12465421110250948690">Recoil provides atomic updates for efficient re-rendering.</span>

</div></div><div class="WaaZC" id="bkmrk-best-practices-for-e" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CE0QAQ" data-ved="2ahUKEwjikfuA4YORAxVFS2wGHffNHfkQo_EKegQITRAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="6015457486435298573">Best Practices for Efficiency:</span></div></div></div><div class="WaaZC" id="bkmrk-regardless-of-the-ch" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc uP58nb MNX06c" data-hveid="CEwQAQ" data-ved="2ahUKEwjikfuA4YORAxVFS2wGHffNHfkQo_EKegQITBAB" style="margin: 10px 0px; font-size: 16px; font-weight: normal; line-height: 24px; letter-spacing: normal;"><span data-huuid="6015457486435297803"><span aria-level="2" role="heading">Regardless of the chosen solution, consider these practices for efficient state management:</span></span></div></div></div><div class="WaaZC" id="bkmrk-minimize-state%3A%C2%A0stor" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <span data-huuid="6015457486435296648">**Minimize State:** </span><span data-huuid="6015457486435296263">Store only necessary data in the global state.</span>
- <span data-huuid="6015457486435295493">**Normalize State:** </span><span data-huuid="6015457486435299204">Structure complex data to avoid duplication and improve update efficiency.</span>
- <span data-huuid="6015457486435298434">**Memoization:** </span><span data-huuid="6015457486435298049">Use `React.memo`, `useMemo`, and `useCallback` to prevent unnecessary re-renders of components and values.</span>
- <span data-huuid="6015457486435297279">**Selectors (Redux/Recoil):** </span><span data-huuid="6015457486435296894">Use selectors to derive data from the state and prevent components from re-rendering when unrelated parts of the state change.</span>
- <span data-huuid="6015457486435296124">**Immutability:** </span><span data-huuid="6015457486435295739">Always update state immutably to ensure predictable behavior and efficient change detection</span>

</div></div>

# react package

# import {useEffect} from "react";

<div class="WaaZC" id="bkmrk-the-statement-import"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CAwQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIDBAB"><span data-huuid="7831568508111237803">The statement `import {useEffect} from "react";` </span><span data-huuid="7831568508111238862">is a JavaScript import declaration used in React applications. </span></div></div></div><div class="rPeykc" data-hveid="CAwQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIDBAB" id="bkmrk-">  
</div><div class="rPeykc" data-hveid="CAwQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIDBAB" id="bkmrk--1"></div><div class="WaaZC" id="bkmrk-purpose%3A"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CAoQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIChAB" role="heading">**<span data-huuid="7831568508111240980">Purpose: </span>**</div></div></div><div class="WaaZC" id="bkmrk-this-line-imports-th"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CA4QAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIDhAB"><span data-huuid="7831568508111239002">This line imports the `useEffect` Hook from the React library. </span><span data-huuid="7831568508111240061">The `useEffect` Hook is a fundamental part of functional components in React, enabling developers to perform "side effects." </span></div></div></div><div class="rPeykc" data-hveid="CA4QAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIDhAB" id="bkmrk--2">  
</div><div class="rPeykc" data-hveid="CA4QAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIDhAB" id="bkmrk--3"></div><div class="WaaZC" id="bkmrk-side-effects-in-reac"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CAgQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQICBAB" role="heading">**<span data-huuid="7831568508111238083">Side Effects in React: </span>**</div></div></div><div class="WaaZC" id="bkmrk-side-effects-are-ope"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc uP58nb MNX06c" data-hveid="CAQQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIBBAB"><span data-huuid="7831568508111240201">Side effects are operations that interact with the outside world or have an impact beyond the component's render cycle. </span><span data-huuid="7831568508111237164">Common examples of side effects include: </span></div></div></div><div class="WaaZC" id="bkmrk-data-fetching%3A-makin"><div class="RJPOee EIJn2" style="animation: none !important;">- <span data-huuid="7831568508111240341">**Data fetching:** </span><span data-huuid="7831568508111237304">Making API calls to retrieve data from a server. </span>
- <span data-huuid="7831568508111239422">**DOM manipulation:** </span><span data-huuid="7831568508111240481">Directly interacting with the browser's Document Object Model (e.g., setting the document title). </span>
- <span data-huuid="7831568508111238503">**Subscriptions:** </span><span data-huuid="7831568508111239562">Setting up event listeners or connecting to external services like WebSockets. </span>
- <span data-huuid="7831568508111237584">**Timers:** </span><span data-huuid="7831568508111238643">Using `setTimeout` or `setInterval`. </span>

</div></div><div class="WaaZC" id="bkmrk-how-useeffect-works%3A"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCQQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIJBAB" role="heading"></div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCQQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIJBAB" role="heading"></div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCQQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIJBAB" role="heading"></div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCQQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIJBAB" role="heading">**<span data-huuid="11612000788613407035">How `useEffect` Works: </span>**</div></div></div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCQQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIJBAB" id="bkmrk--4" role="heading">  
</div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCQQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIJBAB" id="bkmrk--5" role="heading"></div><div class="WaaZC" id="bkmrk-useeffect-takes-two-"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc uP58nb" data-hveid="CCYQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQIJhAB">**<span data-huuid="11612000788613410213"><span aria-level="2" role="heading">`useEffect` takes two arguments:</span> </span>**</div></div></div><div class="WaaZC" id="bkmrk-a-setup-function%3A-th"><div class="RJPOee EIJn2" style="animation: none !important;">- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="11612000788613408836">**A setup function:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="11612000788613408377">This function contains the code for your side effect. </span><span data-huuid="11612000788613407918">It runs after every render of the component (including the initial render) unless its dependencies prevent it from doing so. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="11612000788613407000">**A dependency array (optional):** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="11612000788613410637">This array specifies the values that the effect depends on. </span><span data-huuid="11612000788613410178">If any of these values change between renders, the effect will re-run. </span><span data-huuid="11612000788613409719">An empty dependency array `[]` ensures the effect runs only once after the initial render (similar to `componentDidMount` in class components). </span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-example-usage%3A"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CDYQAQ" data-ved="2ahUKEwi6gcHknrCRAxXTUGwGHTezAGgQo_EKegQINhAB" role="heading"><span data-huuid="15663895085194306514">Example Usage: </span></div></div></div><div class="WaaZC" id="bkmrk--6"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
import { useEffect, useState } from "react";

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

  useEffect(() => {
    // This side effect updates the document title
    document.title = `Count: ${count}`;
  }, [count]); // The effect re-runs whenever 'count' changes

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
}

export default MyComponent;
```

# context hooks in react

<div data-processed="true" data-subtree="aimfl,mfl" id="bkmrk-context-hooks-in-rea" jscontroller="v48bt" jsuid="xKl5Ze_9" style="display: contents;">**Context hooks in React, primarily**</div><div data-processed="true" data-subtree="aimfl,mfl" id="bkmrk-" jscontroller="v48bt" jsuid="xKl5Ze_9" style="display: contents;"></div><div data-processed="true" data-subtree="aimfl,mfl" id="bkmrk--1" jscontroller="v48bt" jsuid="xKl5Ze_9" style="display: contents;"></div>[useContext](https://www.google.com/search?client=ubuntu-sn&channel=fs&q=useContext&mstk=AUtExfAunjEc3Jg-sEBzm2sxLB7-F02T1b7IdzbIMbqIgwAG5BT4cE3xlz_OaBqLs47LPh7O6PHUD_XrXKfMQnzeo4_WPWgLd3jb4xzH7TTTbV9gysdTmHDSV-6cpKC0nSgBsU-ad3U71jFeVpdvDXllUk8j2W2olPEzFWRHqlT2wJjHPilEFAfW8qNiFUc5O_4S9nGFfgBG660U_X2sFO0hTcRINN_GBcTvv21SHJihAI3W7DOa59l8nuHcNsD9_Jr4IZ-xsc7i42dyF3c51gsI1yrs&csui=3&ved=2ahUKEwjnu-_vnbCRAxWMUGwGHUPqPI0QgK4QegQIARAB), <mark class="HxTRcb" data-processed="true">allow functional components to **subscribe to and consume data from React's Context API**</mark>, simplifying global state management by avoiding "prop drilling" (passing props down many levels). You create a `Context` with `React.createContext()`, wrap parts of your app with a `Provider` to pass data down, and then use `useContext(MyContext)` in any nested component to read that data, making it ideal for themes, authentication, or user settings.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="xKl5Ze_h,xKl5Ze_i,xKl5Ze_j"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk--2" jsaction="rcuQ6b:&xKl5Ze_8|npT2md" jscontroller="zcfIf" jsuid="xKl5Ze_8">  
</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--3" jsaction="rcuQ6b:&xKl5Ze_o|npT2md" jscontroller="KHhJQ" jsuid="xKl5Ze_o">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-key-components" jscontroller="a7qCn" jsuid="xKl5Ze_p" role="heading">**Key Components**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--4" jscontroller="a7qCn" jsuid="xKl5Ze_p" role="heading">  
</div>1. <span class="T286Pc" data-processed="true" data-sfc-cp="">**`React.createContext()`**: Creates a Context object, often with a default value, that components can subscribe to.</span>
2. <span class="T286Pc" data-processed="true" data-sfc-cp="">**`<Context.Provider>`**: A component that wraps a part of your component tree and uses the `value` prop to provide data to all descendants.</span>
3. <span class="T286Pc" data-processed="true" data-sfc-cp="">**`useContext(Context)`**: A hook used in functional components to read the current context value from the nearest `Provider` above it in the tree.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="xKl5Ze_18,xKl5Ze_19,xKl5Ze_1a"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--5" jsaction="rcuQ6b:&xKl5Ze_1h|npT2md" jscontroller="KHhJQ" jsuid="xKl5Ze_1h">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-how-it-works-%28simpli" jscontroller="a7qCn" jsuid="xKl5Ze_1i" role="heading">**How It Works (Simplified)**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--6" jscontroller="a7qCn" jsuid="xKl5Ze_1i" role="heading">  
</div>1. <span class="T286Pc" data-processed="true" data-sfc-cp="">**Create Context**:</span><div class="r1PmQe" data-hveid="CAUQAQ" data-processed="true" data-wiz-uids="xKl5Ze_1r,xKl5Ze_1s,xKl5Ze_1t" jscontroller="HP6Sjf" jsuid="xKl5Ze_1q"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">javascript</div></div></div></div>
2. ```
    import { createContext } from 'react';
    const ThemeContext = createContext('light'); // Default value
    
    ```
3. <span class="T286Pc" data-processed="true" data-sfc-cp="">**Provide Context**: Wrap components with the `Provider` high up in the tree.</span><div class="r1PmQe" data-hveid="CAUQBA" data-processed="true" data-wiz-uids="xKl5Ze_21,xKl5Ze_22,xKl5Ze_23" jscontroller="HP6Sjf" jsuid="xKl5Ze_20"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">javascript</div></div></div></div>
4. ```
    function App() {
      return (
        <ThemeContext.Provider value="dark">
          <Toolbar />
        </ThemeContext.Provider>
      );
    }
    
    ```
5. <span class="T286Pc" data-processed="true" data-sfc-cp="">**Consume Context**: Use `useContext` in any child component to get the value.</span><div class="r1PmQe" data-hveid="CAUQBw" data-processed="true" data-wiz-uids="xKl5Ze_2b,xKl5Ze_2c,xKl5Ze_2d" jscontroller="HP6Sjf" jsuid="xKl5Ze_2a"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">javascript</div></div></div></div>

```
import { useContext } from 'react';
function Toolbar() {
  const theme = useContext(ThemeContext); // Gets "dark"
  return <div>The current theme is: {theme}</div>;
}

```

<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="xKl5Ze_2g,xKl5Ze_2h,xKl5Ze_2i"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--7" jsaction="rcuQ6b:&xKl5Ze_2j|npT2md" jscontroller="KHhJQ" jsuid="xKl5Ze_2j">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-benefits" jscontroller="a7qCn" jsuid="xKl5Ze_2k" role="heading">**Benefits**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--8" jscontroller="a7qCn" jsuid="xKl5Ze_2k" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Avoids Prop Drilling**: Eliminates the need to pass props through intermediate components that don't need the data.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Simpler Syntax**: More concise and declarative than older methods (like render props or Consumer components) for functional components.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Global State**: Great for sharing data like themes, user info, or language settings across an application.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="xKl5Ze_2y,xKl5Ze_2z,xKl5Ze_30"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--9" jsaction="rcuQ6b:&xKl5Ze_35|npT2md" jscontroller="KHhJQ" jsuid="xKl5Ze_35">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-best-practice%3A-custo" jscontroller="a7qCn" jsuid="xKl5Ze_36" role="heading">**Best Practice: Custom Hooks**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--10" jscontroller="a7qCn" jsuid="xKl5Ze_36" role="heading">  
</div><div class="Y3BBE" data-hveid="CAkQAA" data-processed="true" data-sfc-cp="" id="bkmrk-for-cleaner-code%2C-es" jsaction="rcuQ6b:&xKl5Ze_3a|npT2md" jscontroller="zcfIf" jsuid="xKl5Ze_3a">For cleaner code, especially with complex contexts (like theme + setter), create a custom hook that encapsulates the `useContext` call and error handling (e.g., checking for null if used outside a provider).<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="xKl5Ze_3c,xKl5Ze_3d,xKl5Ze_3e"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span></div><div class="Y3BBE" data-hveid="CAkQAA" data-processed="true" data-sfc-cp="" id="bkmrk--11" jsaction="rcuQ6b:&xKl5Ze_3a|npT2md" jscontroller="zcfIf" jsuid="xKl5Ze_3a">  
</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--12" jsaction="rcuQ6b:&xKl5Ze_3g|npT2md" jscontroller="KHhJQ" jsuid="xKl5Ze_3g">  
</div><div class="r1PmQe" data-hveid="CAwQAA" data-processed="true" data-wiz-uids="xKl5Ze_7e,xKl5Ze_7f,xKl5Ze_7g" id="bkmrk-javascript" jscontroller="HP6Sjf" jsuid="xKl5Ze_7d"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">javascript</div></div></div></div>```
// useTheme.js
import { useContext } from 'react';
import { ThemeContext } from './ThemeContext';

export function useTheme() {
  const context = useContext(ThemeContext);
  if (context === undefined) {
    throw new Error('useTheme must be used within a ThemeProvider');
  }
  return context;
}

```

# @types/react

`@types/react` is the <mark class="HxTRcb" data-processed="true">npm package containing TypeScript definitions for the React library</mark>, essential for building React apps with TypeScript to get type-checking for components, props, hooks (like `useState`, `useEffect`), and rendering types (like `ReactNode`). It provides the necessary structure for TypeScript to understand React's API, enabling features like autocompletion and catching errors before runtime, with types such as `React.FC` for functional components or `React.ReactNode` for renderable content.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="aAJ2Qe_l,aAJ2Qe_m,aAJ2Qe_n"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&aAJ2Qe_8|npT2md" jscontroller="zcfIf" jsuid="aAJ2Qe_8">  
</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--1" jsaction="rcuQ6b:&aAJ2Qe_t|npT2md" jscontroller="KHhJQ" jsuid="aAJ2Qe_t">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-what-it-does%3A" jscontroller="a7qCn" jsuid="aAJ2Qe_u" role="heading">**What it does:**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--2" jscontroller="a7qCn" jsuid="aAJ2Qe_u" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Type Safety:** Gives TypeScript knowledge of React's functions, components, and props.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Hooks Support:** Includes types for all built-in React hooks, allowing their correct usage.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Component Definition:** Helps define component props, including `children` (often as `React.ReactNode`).</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Rendering Types:** Defines types like `React.Element`, `React.ReactNode` (anything renderable), `JSX.Element`, etc..</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="aAJ2Qe_1g,aAJ2Qe_1h,aAJ2Qe_1i"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--3" jsaction="rcuQ6b:&aAJ2Qe_1o|npT2md" jscontroller="KHhJQ" jsuid="aAJ2Qe_1o">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-how-to-use-it%3A" jscontroller="a7qCn" jsuid="aAJ2Qe_1p" role="heading">**How to use it:**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--4" jscontroller="a7qCn" jsuid="aAJ2Qe_1p" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">Install it as a development dependency: `npm install --save-dev @types/react` or `yarn add @types/react`.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">It's typically installed alongside `@types/react-dom` for full type support in your React+TypeScript projects.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="aAJ2Qe_21,aAJ2Qe_22,aAJ2Qe_23"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--5" jsaction="rcuQ6b:&aAJ2Qe_26|npT2md" jscontroller="KHhJQ" jsuid="aAJ2Qe_26">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-key-types-you%27ll-use" jscontroller="a7qCn" jsuid="aAJ2Qe_27" role="heading">**Key types you'll use:**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--6" jscontroller="a7qCn" jsuid="aAJ2Qe_27" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`React.FC<Props>`**: For functional components.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`React.ReactNode`**: For props that accept anything renderable (children, content).</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`React.HTMLAttributes<T>`**: For standard HTML attributes on components.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="aAJ2Qe_2o,aAJ2Qe_2p,aAJ2Qe_2q"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--7" jsaction="rcuQ6b:&aAJ2Qe_2u|npT2md" jscontroller="KHhJQ" jsuid="aAJ2Qe_2u">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-important-note%3A" jscontroller="a7qCn" jsuid="aAJ2Qe_2v" role="heading">**Important Note:**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--8" jscontroller="a7qCn" jsuid="aAJ2Qe_2v" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">Ensure your `@types/react` version matches your `react` version for consistency, as mismatches can cause issues (e.g., React 18 changes required corresponding type updates)</span>

# import React from 'react'

<div data-subtree="aimfl,mfl" id="bkmrk-import-react-from-%27r" jscontroller="v48bt" jsuid="jrFusd_9" style="display: contents;">`import React from 'react'`</div><mark class="HxTRcb">is a JavaScript statement to bring the React library into your file</mark>, historically required to use JSX (like `<div>`) because it converts to `React.createElement()`, though newer React versions with the "new JSX transform" (React 17+) often make it optional for basic JSX, but it's still needed for Hooks (like `useState`) and other exports, with `import * as React from 'react'` also common for importing everything into a `React` object.<span class="uJ19be notranslate" data-wiz-uids="jrFusd_h,jrFusd_i,jrFusd_j"><span class="vKEkVd" data-animation-atomic=""> </span></span>

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&jrFusd_8|npT2md" jscontroller="zcfIf" jsuid="jrFusd_8">  
</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--1" jsaction="rcuQ6b:&jrFusd_o|npT2md" jscontroller="KHhJQ" jsuid="jrFusd_o">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-what-it-does" jscontroller="a7qCn" jsuid="jrFusd_p" role="heading">**What it does**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--2" jscontroller="a7qCn" jsuid="jrFusd_p" role="heading">  
</div>- <span class="T286Pc" data-sfc-cp="">**Imports React:** It makes the `React` object, containing methods like `createElement`, available in your component.</span>
- <span class="T286Pc" data-sfc-cp="">**Enables JSX:** Before React 17, this line was essential because JSX syntax (e.g., `<p>Hello</p>`) gets transformed into `React.createElement(<p>, null, 'Hello')`.</span><span class="uJ19be notranslate" data-wiz-uids="jrFusd_14,jrFusd_15,jrFusd_16"><span class="vKEkVd" data-animation-atomic=""> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--3" jsaction="rcuQ6b:&jrFusd_1a|npT2md" jscontroller="KHhJQ" jsuid="jrFusd_1a">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-modern-variations-an" jscontroller="a7qCn" jsuid="jrFusd_1b" role="heading">**Modern variations and when to use them**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--4" jscontroller="a7qCn" jsuid="jrFusd_1b" role="heading">  
</div>- <span class="T286Pc" data-sfc-cp="">**`import React from 'react'`:** Imports the default export (the whole library) and names it `React`. Still needed for Hooks.</span>
- <span class="T286Pc" data-sfc-cp="">**`import * as React from 'react'`:** Imports all named exports into a single `React` object. Useful in TypeScript or with specific bundler setups.</span>
- <span class="T286Pc" data-sfc-cp="">**No import (for simple components):** With React 17+, the new JSX transform handles basic JSX without needing the import, but you still need it for hooks.</span>
- <span class="T286Pc" data-sfc-cp="">**Specific imports:** For efficiency, import only what you need, e.g., `import { useState } from 'react'`.</span><span class="uJ19be notranslate" data-wiz-uids="jrFusd_1x,jrFusd_1y,jrFusd_1z"><span class="vKEkVd" data-animation-atomic=""> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--5" jsaction="rcuQ6b:&jrFusd_25|npT2md" jscontroller="KHhJQ" jsuid="jrFusd_25">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-example-%28classic%29" jscontroller="a7qCn" jsuid="jrFusd_26" role="heading">**Example (Classic)**</div><div class="r1PmQe" data-hveid="CAkQAA" data-processed="true" data-wiz-uids="jrFusd_4m,jrFusd_4n,jrFusd_4o" id="bkmrk--6" jscontroller="HP6Sjf" jsuid="jrFusd_4l"><div><div class="pHpOfb" data-animation-atomic=""></div></div></div>```
import React from 'react'; // Required for React.useState

function Counter() {
  const [count, setCount] = React.useState(0); // Uses React.useState
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
}

```

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--7" jsaction="rcuQ6b:&jrFusd_4r|npT2md" jscontroller="KHhJQ" jsuid="jrFusd_4r">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-example-%28modern---no" jscontroller="a7qCn" jsuid="jrFusd_4s" role="heading">**Example (Modern - no import needed for basic JSX)**</div><div class="r1PmQe" data-hveid="CAsQAA" data-processed="true" data-wiz-uids="jrFusd_4y,jrFusd_4z,jrFusd_50" id="bkmrk--8" jscontroller="HP6Sjf" jsuid="jrFusd_4x"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">  
</div></div></div></div>```
// import React from 'react'; // Not strictly needed for just JSX

function Greeting({ name }) {
  // No React. prefix needed for useState with this setup
  return <h1>Hello, {name}!</h1>;
}

```

# createbrowserrouter in react

<div data-processed="true" data-subtree="aimfl,mfl" id="bkmrk-createbrowserrouter" jscontroller="v48bt" jsuid="SZleKb_9" style="display: contents;">`createBrowserRouter`</div>in React Router (v6.4+) <mark class="HxTRcb" data-processed="true">creates a router using a data-driven approach (array of route objects) instead of JSX</mark>, enabling powerful features like data loading (loaders) and mutations (actions), and is the recommended modern way for web apps by managing history via the HTML5 History API for clean URLs. You define routes as objects with `path` and `element` (or `children`) and pass them to `createBrowserRouter`, then wrap your app with the `RouterProvider` component.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="SZleKb_h,SZleKb_i,SZleKb_j"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&SZleKb_8|npT2md" jscontroller="zcfIf" jsuid="SZleKb_8">  
</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--1" jsaction="rcuQ6b:&SZleKb_p|npT2md" jscontroller="KHhJQ" jsuid="SZleKb_p">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-how-to-use-createbro" jscontroller="a7qCn" jsuid="SZleKb_q" role="heading">**How to Use `createBrowserRouter`**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--2" jscontroller="a7qCn" jsuid="SZleKb_q" role="heading">  
</div>1. <span class="T286Pc" data-processed="true" data-sfc-cp="">**Install React Router:**</span><div class="r1PmQe" data-hveid="CAMQAQ" data-processed="true" data-wiz-uids="SZleKb_10,SZleKb_11,SZleKb_12" jscontroller="HP6Sjf" jsuid="SZleKb_z"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">bash</div></div></div></div>
2. ```
    npm install react-router-dom
    # or
    yarn add react-router-dom
    
    ```
3. <span class="T286Pc" data-processed="true" data-sfc-cp="">**Define Your Routes (e.g., in `router.js` or `index.js`):**</span><div class="r1PmQe" data-hveid="CAMQBA" data-processed="true" data-wiz-uids="SZleKb_1b,SZleKb_1c,SZleKb_1d" jscontroller="HP6Sjf" jsuid="SZleKb_1a"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">javascript</div></div></div></div>
4. ```
    import { createBrowserRouter } from 'react-router-dom';
    import Root from './routes/Root'; // Your main layout component
    import Home from './routes/Home';
    import About from './routes/About';
    import ErrorPage from './routes/ErrorPage';
    
    const router = createBrowserRouter([
      {
        path: "/",
        element: <Root />,
        errorElement: <ErrorPage />,
        children: [ // Nested routes
          { index: true, element: <Home /> }, // Renders <Home> at '/'
          { path: "about", element: <About /> },
          { path: "users/:userId", element: <UserProfile /> }, // Dynamic route
        ],
      },
    ]);
    
    export default router;
    
    ```
    
    
    - <span class="T286Pc" data-processed="true" data-sfc-cp="">**`path`**: The URL segment. `index: true` is for the default child route.</span>
    - <span class="T286Pc" data-processed="true" data-sfc-cp="">**`element`**: The component to render for that path.</span>
    - <span class="T286Pc" data-processed="true" data-sfc-cp="">**`children`**: For nested routes, uses `<Outlet />` in the parent.</span>
5. <span class="T286Pc" data-processed="true" data-sfc-cp="">**Provide the Router (in `index.js` or `App.js`):**</span><div class="r1PmQe" data-hveid="CAMQCg" data-processed="true" data-wiz-uids="SZleKb_21,SZleKb_22,SZleKb_23" jscontroller="HP6Sjf" jsuid="SZleKb_20"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">javascript</div></div></div></div>

```
import React from 'react';
import ReactDOM from 'react-dom/client';
import { RouterProvider } from 'react-router-dom';
import router from './router'; // Your router config

ReactDOM.createRoot(document.getElementById('root')).render(
  <React.StrictMode>
    <RouterProvider router={router} />
  </React.StrictMode>,
);

```

<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="SZleKb_26,SZleKb_27,SZleKb_28"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--3" jsaction="rcuQ6b:&SZleKb_2c|npT2md" jscontroller="KHhJQ" jsuid="SZleKb_2c">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-key-advantages-%28vs.-" jscontroller="a7qCn" jsuid="SZleKb_2d" role="heading">**Key Advantages (vs. `<BrowserRouter>`/JSX Routes)**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--4" jscontroller="a7qCn" jsuid="SZleKb_2d" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Data Layer:** Supports `loader` functions for fetching data before rendering, ensuring components get data immediately.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Data Mutations:** Supports `action` functions for POST/PUT/DELETE requests, improving data flow.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Flexibility:** Configure routes as JS objects (data) instead of JSX, separating concerns.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Future-Proof:** Recommended by React Router as the modern direction</span>

# useMemo,useLocation from react

<div class="WaaZC" id="bkmrk-usememo-and-uselocat"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CAUQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIBRAB"><span data-huuid="9465597073531100809">`useMemo` and `useLocation` are two distinct hooks in the React ecosystem, serving different purposes. </span></div></div></div><div class="rPeykc" data-hveid="CAUQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIBRAB" id="bkmrk-">  
</div><div class="rPeykc" data-hveid="CAUQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIBRAB" id="bkmrk--1"></div><div class="WaaZC" id="bkmrk-usememo-%28from-react%29"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CAIQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIAhAB" role="heading">**<span data-huuid="9465597073531098711">`useMemo` (from `react`) </span>**</div></div></div><div class="WaaZC" id="bkmrk-usememo-is-a-react-h"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CAkQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQICRAB"><span data-huuid="9465597073531100709">`useMemo` is a React Hook that allows for memoization of a value. </span><span data-huuid="9465597073531099660">This means it caches the result of an expensive calculation and only re-runs the calculation if its dependencies change. </span><span data-huuid="9465597073531098611">This can significantly improve performance by preventing unnecessary re-calculations on every render. </span></div></div></div><div class="WaaZC" id="bkmrk--2"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
import React, { useMemo } from 'react';

function MyComponent({ data }) {
  // Expensive calculation that only re-runs if 'data' changes
  const processedData = useMemo(() => {
    // Perform complex data processing here
    return data.map(item => item.value * 2);
  }, [data]); // Dependencies array

  return (
    <div>
      {/* Render processedData */}
      {processedData.map((item, index) => (
        <p key={index}>{item}</p>
      ))}
    </div>
  );
}
```

<div aria-level="3" class="rPeykc pyPiTc" data-hveid="CBAQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIEBAB" id="bkmrk--3" role="heading">  
</div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CBAQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIEBAB" id="bkmrk--4" role="heading"></div><div class="WaaZC" id="bkmrk-uselocation-%28from-re"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CBAQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIEBAB" role="heading"><span data-huuid="9404912379262324393">**`useLocation` (from `react-router-dom`)** </span></div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CBAQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIEBAB" role="heading">  
</div></div></div><div class="WaaZC" id="bkmrk-uselocation-is-a-hoo"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CBIQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIEhAB"><span data-huuid="9404912379262323967">`useLocation` is a hook provided by the `react-router-dom` library, not directly from `react`. </span><span data-huuid="9404912379262321706">It allows you to access the current URL's `location` object, which contains information about the current route. </span><span data-huuid="9404912379262323541">This information includes `pathname`, `search` (query parameters), `hash`, and `state` (data passed during navigation). </span></div><div class="rPeykc" data-hveid="CBIQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIEhAB">  
</div></div></div>```
import React from 'react';
import { useLocation } from 'react-router-dom';

function CurrentRouteInfo() {
  const location = useLocation();

  return (
    <div>
      <p>Pathname: {location.pathname}</p>
      <p>Search Query: {location.search}</p>
      <p>Hash: {location.hash}</p>
      {/* Access state data if available */}
      {location.state && <p>State Data: {JSON.stringify(location.state)}</p>}
    </div>
  );
}
```

<div class="WaaZC" id="bkmrk-key-differences%3A"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CBsQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIGxAB" role="heading"></div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CBsQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIGxAB" role="heading"></div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CBsQAQ" data-ved="2ahUKEwjYoKjForCRAxVDR2wGHdsBJzUQo_EKegQIGxAB" role="heading">**<span data-huuid="5209593288003989533">Key Differences: </span>**</div></div></div><div class="WaaZC" id="bkmrk-origin%3A-usememo-is-a"><div class="RJPOee EIJn2" style="animation: none !important;">- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="5209593288003991088">**Origin:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="5209593288003990241">`useMemo` is a core React hook, while `useLocation` is part of `react-router-dom`. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="5209593288003992643">**Purpose:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="5209593288003991796">`useMemo` optimizes performance by memoizing values, while `useLocation` provides access to route information. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="5209593288003990102">**Dependencies:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="5209593288003993351">`useMemo` takes a dependencies array to determine when to re-calculate, while `useLocation` automatically updates when the URL changes</span></div></div></div></div>

</div></div>

# React Router DOM

# React Router DOM

<span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">React Router DOM is a widely used library for handling routing in React applications, particularly those designed for web browsers. It provides a set of components and hooks that enable declarative navigation and URL management within single-page applications (SPAs).</span>

<span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Key features and functionalities of React Router DOM:</span>

- <span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Declarative Routing:</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> It allows defining routes as components, making the routing logic intuitive and integrated with the React component tree.</span>
- <span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Browser-Specific Components:</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> It includes components like </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">&lt;BrowserRouter&gt;</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">&lt;Link&gt;</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, and </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">&lt;NavLink&gt;</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> that specifically interact with the browser's history API and render standard HTML elements for navigation.</span>
- <span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Dynamic Routing:</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> Enables the creation of routes with dynamic parameters, allowing for flexible URL structures and data fetching based on the route.</span>
- <span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Nested Routes:</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> Supports the creation of hierarchical routes, where parent routes can render child routes, facilitating complex application layouts.</span>
- <span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Programmatic Navigation:</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> Provides hooks like </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">useNavigate</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> for imperative navigation, allowing redirection or programmatically changing routes based on user actions or application logic.</span>
- <span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Route Guards and Authentication:</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> Can be used to implement route protection, ensuring users are authenticated or authorized before accessing certain parts of the application.</span>

**<span style="font-size: 11pt; font-family: Arial, sans-serif; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Installation:</span>**

<span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">To use React Router DOM in a React project, it needs to be installed as a dependency:</span>

<div class="WaaZC" id="bkmrk--1"><div class="bsmXxe" id="bkmrk--2" role="none"><div class="rPeykc" data-hveid="CIIBEAE" data-ved="2ahUKEwigrJ7QnbCRAxUXcGwGHVdrFZsQo_EKegUIggEQAQ">  
</div></div></div><div class="WaaZC" id="bkmrk-code"><div class="bsmXxe" id="bkmrk-code-1" role="none"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
npm install react-router-dom
```

<div class="WaaZC" id="bkmrk-basic-usage-example%3A"><div class="bsmXxe" id="bkmrk-basic-usage-example%3A-1" role="none"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CHYQAQ" data-ved="2ahUKEwigrJ7QnbCRAxUXcGwGHVdrFZsQo_EKegQIdhAB" role="heading"><span data-huuid="613062625343153085">Basic Usage Example: </span></div></div></div><div class="WaaZC" id="bkmrk-code-2"><div class="bsmXxe" id="bkmrk-code-3" role="none"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';

function App() {
  return (
    <BrowserRouter>
      <nav>
        <Link to="/">Home</Link>
        <Link to="/about">About</Link>
      </nav>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/about" element={<About />} />
      </Routes>
    </BrowserRouter>
  );
}

function Home() {
  return <h1>Welcome to the Home Page!</h1>;
}

function About() {
  return <h1>About Us</h1>;
}

export default App;
```

**<span style="font-size: 11pt; font-family: Arial, sans-serif; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Note on React Router v7:  
  
</span>**

<span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">With React Router v7, the </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">react-router-dom</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> package primarily re-exports the contents of </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">react-router</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. While </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">react-router-dom</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> can still be used for compatibility with older projects or during upgrades, new projects are encouraged to use </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">react-router</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> directly for web applications, as the browser-specific functionalities are now integrated within the core </span><span style="font-size: 11pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">react-router</span><span style="font-size: 11pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> package</span>

---

`react-router-dom` enables declarative, component-based routing in React web apps, allowing single-page applications (SPAs) to navigate between different views/components without full page reloads, managing browser history, supporting [dynamic URLs](https://www.google.com/search?client=ubuntu-sn&channel=fs&q=dynamic+URLs&mstk=AUtExfAqlfGSVGnW6BQg5Ua3eHb7dMenp-XMQx4C3RZSIZoICpw31F5754-0-su852oVmK6tLMuxm7cvfcNt-FBjsPkf8DqBYDj0Ui2vJAV2HBoC-U6g3KT-YjHZhjkZ-f8etErgi1LHybVneVI2low8U-FgbWxip19g_p52oUnE_5Kde0-eoLjkK_Oh7Putb3eQD0SsFWNK6t_lGni7YZbs7nVHvEzZxfQBOY2Y4VKNDAAWi9zzc248NGPxjYyAUU-ohRSoA199llzH7Sh5dI5vLhWc&csui=3&ved=2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQgK4QegQIARAD) (with parameters), creating [nested routes](https://www.google.com/search?client=ubuntu-sn&channel=fs&q=nested+routes&mstk=AUtExfAqlfGSVGnW6BQg5Ua3eHb7dMenp-XMQx4C3RZSIZoICpw31F5754-0-su852oVmK6tLMuxm7cvfcNt-FBjsPkf8DqBYDj0Ui2vJAV2HBoC-U6g3KT-YjHZhjkZ-f8etErgi1LHybVneVI2low8U-FgbWxip19g_p52oUnE_5Kde0-eoLjkK_Oh7Putb3eQD0SsFWNK6t_lGni7YZbs7nVHvEzZxfQBOY2Y4VKNDAAWi9zzc248NGPxjYyAUU-ohRSoA199llzH7Sh5dI5vLhWc&csui=3&ved=2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQgK4QegQIARAE) for complex layouts, handling authentication (route guards), and providing tools for bookmarkable links and programmatic navigation via hooks like [useNavigate](https://www.google.com/search?client=ubuntu-sn&channel=fs&q=useNavigate&mstk=AUtExfAqlfGSVGnW6BQg5Ua3eHb7dMenp-XMQx4C3RZSIZoICpw31F5754-0-su852oVmK6tLMuxm7cvfcNt-FBjsPkf8DqBYDj0Ui2vJAV2HBoC-U6g3KT-YjHZhjkZ-f8etErgi1LHybVneVI2low8U-FgbWxip19g_p52oUnE_5Kde0-eoLjkK_Oh7Putb3eQD0SsFWNK6t_lGni7YZbs7nVHvEzZxfQBOY2Y4VKNDAAWi9zzc248NGPxjYyAUU-ohRSoA199llzH7Sh5dI5vLhWc&csui=3&ved=2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQgK4QegQIARAF) (formerly `useHistory`) and [useLocation](https://www.google.com/search?client=ubuntu-sn&channel=fs&q=useLocation&mstk=AUtExfAqlfGSVGnW6BQg5Ua3eHb7dMenp-XMQx4C3RZSIZoICpw31F5754-0-su852oVmK6tLMuxm7cvfcNt-FBjsPkf8DqBYDj0Ui2vJAV2HBoC-U6g3KT-YjHZhjkZ-f8etErgi1LHybVneVI2low8U-FgbWxip19g_p52oUnE_5Kde0-eoLjkK_Oh7Putb3eQD0SsFWNK6t_lGni7YZbs7nVHvEzZxfQBOY2Y4VKNDAAWi9zzc248NGPxjYyAUU-ohRSoA199llzH7Sh5dI5vLhWc&csui=3&ved=2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQgK4QegQIARAG), all through DOM-aware components like `<BrowserRouter>`, `<Link>`, and `<Route>`.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="zUVu8b_n,zUVu8b_o,zUVu8b_p"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk--4" jsaction="rcuQ6b:&zUVu8b_8|npT2md" jscontroller="zcfIf" jsuid="zUVu8b_8">  
</div><div class="Y3BBE" data-hveid="CAIQAA" data-processed="true" data-sfc-cp="" id="bkmrk-this-video-provides-" jsaction="rcuQ6b:&zUVu8b_v|npT2md" jscontroller="zcfIf" jsuid="zUVu8b_v">This video provides a complete tutorial on the basics of React Router: <div class="" data-processed="true" data-wiz-uids="zUVu8b_x,zUVu8b_y" jscontroller="uDeH3" jsuid="zUVu8b_w"><div data-hveid="CAIQAQ" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQ-bUQegQIAhAB"><div data-processed="true"><div class="Q2WBBe" data-processed="true" jsuid="zUVu8b_y"><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQypYSegQIAhAC" jsuid="zUVu8b_x" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="zUVu8b_10" jsaction="rcuQ6b:&zUVu8b_z|npT2md" jscallback="gfNXHe:&zUVu8b_w:U8wGUb" jscontroller="wMmv4c" jsuid="zUVu8b_z"></div></div></div></div></div></div></div><div class="n7j80c YkW4Kb" data-processed="true" id="bkmrk--5" jscontroller="ItMuwb" jsuid="zUVu8b_11" style="--segment-bar-offset: 12px;"><div class="s3ITrd" data-processed="true" style="left: 5%; width: 2%;"></div></div><div class="dumoDb YkW4Kb" data-processed="true" id="bkmrk--6"><div class="CaQWce" data-processed="true" jscontroller="sRLmTc" jsuid="zUVu8b_12"><svg fill="currentColor" height="18px" viewbox="0 -960 960 960" width="18px" xmlns="http://www.w3.org/2000/svg"></svg></div></div><div class="Y3BBE" data-hveid="CAIQAA" data-processed="true" data-sfc-cp="" id="bkmrk-greatstack-youtube-%E2%80%A2" jsaction="rcuQ6b:&zUVu8b_v|npT2md" jscontroller="zcfIf" jsuid="zUVu8b_v"><div class="" data-processed="true" data-wiz-uids="zUVu8b_x,zUVu8b_y" jscontroller="uDeH3" jsuid="zUVu8b_w"><div data-hveid="CAIQAQ" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQ-bUQegQIAhAB"><div data-processed="true"><div class="Q2WBBe" data-processed="true" jsuid="zUVu8b_y"><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQypYSegQIAhAC" jsuid="zUVu8b_x" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="zUVu8b_10" jsaction="rcuQ6b:&zUVu8b_z|npT2md" jscallback="gfNXHe:&zUVu8b_w:U8wGUb" jscontroller="wMmv4c" jsuid="zUVu8b_z"><div class="nrdPJf" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQtbEQegQIAhAD" jsaction="click:&zUVu8b_z|T2P31d" jsuid="zUVu8b_10" role="button" tabindex="0"><div class="dumoDb YkW4Kb" data-processed="true"></div></div></div></div><div data-processed="true">[<div class="RhEuY" data-processed="true"><div class="SWvopd" data-processed="true" jscontroller="aNJZAb" jsuid="zUVu8b_15"><div class="Lki2rc" data-processed="true"></div><div class="JccCTc xG6cCf" data-processed="true"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="zUVu8b_17">![](https://articles.ravapps.com/uploads/images/gallery/2025-12/9FeazcIAJ3GOBkqi-embedded-image-3cbb2zct.png)</div></div></div><div data-processed="true"><div class="SrjfCd" data-processed="true">GreatStack</div><div class="Pcl3Vd" data-processed="true">YouTube • 9 Oct 2024</div></div></div>](https://www.youtube.com/watch?v=943D7U74_sQ&t=323)</div></div></div></div></div></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--7" jsaction="rcuQ6b:&zUVu8b_18|npT2md" jscontroller="KHhJQ" jsuid="zUVu8b_18">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-core-uses-%26-features" jscontroller="a7qCn" jsuid="zUVu8b_19" role="heading">Core Uses &amp; Features</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--8" jscontroller="a7qCn" jsuid="zUVu8b_19" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Client-Side Routing:** Maps URLs to specific components, rendering them without server requests, perfect for SPAs.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**No Page Reloads:** Smooth transitions between "pages" using JavaScript, enhancing user experience.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**URL Management:** Creates clean, bookmarkable URLs and uses the browser's history stack.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Declarative Routing:** Defines routes using components like `<BrowserRouter>`, `<Routes>`, and `<Route>`.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Dynamic Routes:** Handles URLs with parameters (e.g., `/users/:id`) to show dynamic content.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Nested Routes:** Organizes complex UIs by rendering child routes within parent routes.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Programmatic Navigation:** Navigate programmatically with [useNavigate](https://www.google.com/search?client=ubuntu-sn&channel=fs&q=useNavigate&mstk=AUtExfAqlfGSVGnW6BQg5Ua3eHb7dMenp-XMQx4C3RZSIZoICpw31F5754-0-su852oVmK6tLMuxm7cvfcNt-FBjsPkf8DqBYDj0Ui2vJAV2HBoC-U6g3KT-YjHZhjkZ-f8etErgi1LHybVneVI2low8U-FgbWxip19g_p52oUnE_5Kde0-eoLjkK_Oh7Putb3eQD0SsFWNK6t_lGni7YZbs7nVHvEzZxfQBOY2Y4VKNDAAWi9zzc248NGPxjYyAUU-ohRSoA199llzH7Sh5dI5vLhWc&csui=3&ved=2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQgK4QegQIBBAH) (or `useHistory`) or declaratively with `<Navigate>`.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Data Loading:** Modern versions (v7+) allow data fetching directly in route definitions (loaders/actions).</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="zUVu8b_29,zUVu8b_2a,zUVu8b_2b"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAUQAA" data-processed="true" data-sfc-cp="" id="bkmrk-you-can-watch-this-v" jsaction="rcuQ6b:&zUVu8b_2k|npT2md" jscontroller="zcfIf" jsuid="zUVu8b_2k">You can watch this video to see how to perform simple navigation between pages in React: <div class="" data-processed="true" data-wiz-uids="zUVu8b_2m,zUVu8b_2n" jscontroller="uDeH3" jsuid="zUVu8b_2l"><div data-hveid="CAUQAQ" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQ-bUQegQIBRAB"><div data-processed="true"><div class="Q2WBBe" data-processed="true" jsuid="zUVu8b_2n"><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQypYSegQIBRAC" jsuid="zUVu8b_2m" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="zUVu8b_2p" jsaction="rcuQ6b:&zUVu8b_2o|npT2md" jscallback="gfNXHe:&zUVu8b_2l:U8wGUb" jscontroller="wMmv4c" jsuid="zUVu8b_2o"></div></div></div></div></div></div></div><div class="Y3BBE" data-hveid="CAUQAA" data-processed="true" data-sfc-cp="" id="bkmrk-tech-with-nanor-yout" jsaction="rcuQ6b:&zUVu8b_2k|npT2md" jscontroller="zcfIf" jsuid="zUVu8b_2k"><div class="" data-processed="true" data-wiz-uids="zUVu8b_2m,zUVu8b_2n" jscontroller="uDeH3" jsuid="zUVu8b_2l"><div data-hveid="CAUQAQ" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQ-bUQegQIBRAB"><div data-processed="true"><div class="Q2WBBe" data-processed="true" jsuid="zUVu8b_2n"><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQypYSegQIBRAC" jsuid="zUVu8b_2m" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="zUVu8b_2p" jsaction="rcuQ6b:&zUVu8b_2o|npT2md" jscallback="gfNXHe:&zUVu8b_2l:U8wGUb" jscontroller="wMmv4c" jsuid="zUVu8b_2o"><div class="nrdPJf" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQtbEQegQIBRAD" jsaction="click:&zUVu8b_2o|T2P31d" jsuid="zUVu8b_2p" role="button" tabindex="0"><div class="dumoDb YkW4Kb" data-processed="true"></div></div></div></div><div data-processed="true">[<div class="RhEuY" data-processed="true"><div class="SWvopd" data-processed="true" jscontroller="aNJZAb" jsuid="zUVu8b_2t"><div class="Lki2rc" data-processed="true"></div><div class="JccCTc xG6cCf" data-processed="true"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="zUVu8b_2v">![](https://articles.ravapps.com/uploads/images/gallery/2025-12/4Sfk3201CnIeTdLG-embedded-image-fojoa7n6.png)</div></div></div><div data-processed="true"><div class="SrjfCd" data-processed="true">Tech With Nanor</div><div class="Pcl3Vd" data-processed="true">YouTube • 15 Jun 2025</div></div></div>](https://www.youtube.com/watch?v=X3It9vgZqcU)</div></div></div></div></div></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--9" jsaction="rcuQ6b:&zUVu8b_2w|npT2md" jscontroller="KHhJQ" jsuid="zUVu8b_2w">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-key-components-%26-hoo" jscontroller="a7qCn" jsuid="zUVu8b_2x" role="heading">Key Components &amp; Hooks (v6+)</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--10" jscontroller="a7qCn" jsuid="zUVu8b_2x" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`<BrowserRouter>`:** The main router that uses the HTML5 History API.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`<Routes>` / `<Route>`:** Renders components for matching paths.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`<Link>` / `<NavLink>`:** Renders `<a>` tags for navigation without page reloads.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`useNavigate`:** Hook for imperative navigation.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`useParams`:** Hook to access dynamic URL parameters.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`useLocation`:** Hook to get current location data.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`Outlet`:** Renders nested child routes.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="zUVu8b_3x,zUVu8b_3y,zUVu8b_3z"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--11" jsaction="rcuQ6b:&zUVu8b_45|npT2md" jscontroller="KHhJQ" jsuid="zUVu8b_45">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-when-to-use-it" jscontroller="a7qCn" jsuid="zUVu8b_46" role="heading">When to Use It</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--12" jscontroller="a7qCn" jsuid="zUVu8b_46" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Web Applications:** Use `react-router-dom` for any React app running in a web browser.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Complex Layouts:** Ideal for apps with dashboards, multi-step forms, or admin panels.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Single-Page Apps (SPAs):** Essential for building SPAs that feel like traditional multi-page sites.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="zUVu8b_58,zUVu8b_59,zUVu8b_5a"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAwQAA" data-processed="true" data-sfc-cp="" id="bkmrk-this-video-provides--1" jsaction="rcuQ6b:&zUVu8b_80|npT2md" jscontroller="zcfIf" jsuid="zUVu8b_80">This video provides a complete tutorial on the basics of React Router: <div class="" data-processed="true" data-wiz-uids="zUVu8b_82,zUVu8b_83" jscontroller="uDeH3" jsuid="zUVu8b_81"><div data-hveid="CAwQAQ" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQ-bUQegQIDBAB"><div data-processed="true"><div class="Q2WBBe" data-processed="true" jsuid="zUVu8b_83"><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQypYSegQIDBAC" jsuid="zUVu8b_82" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="zUVu8b_85" jsaction="rcuQ6b:&zUVu8b_84|npT2md" jscallback="gfNXHe:&zUVu8b_81:U8wGUb" jscontroller="wMmv4c" jsuid="zUVu8b_84"></div></div></div></div></div></div></div><div class="n7j80c YkW4Kb" data-processed="true" id="bkmrk--13" jscontroller="ItMuwb" jsuid="zUVu8b_86" style="--segment-bar-offset: 12px;"><div class="s3ITrd" data-processed="true" style="left: 5%; width: 2%;"></div></div><div class="dumoDb YkW4Kb" data-processed="true" id="bkmrk--14"><div class="CaQWce" data-processed="true" jscontroller="sRLmTc" jsuid="zUVu8b_87"><svg fill="currentColor" height="18px" viewbox="0 -960 960 960" width="18px" xmlns="http://www.w3.org/2000/svg"></svg></div></div><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQypYSegQIDBAC" id="bkmrk--15" jsuid="zUVu8b_82" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="zUVu8b_85" jsaction="rcuQ6b:&zUVu8b_84|npT2md" jscallback="gfNXHe:&zUVu8b_81:U8wGUb" jscontroller="wMmv4c" jsuid="zUVu8b_84"><div class="nrdPJf" data-processed="true" data-ved="2ahUKEwjQ7t6rnrCRAxUqSWwGHTrtAugQtbEQegQIDBAD" jsaction="click:&zUVu8b_84|T2P31d" jsuid="zUVu8b_85" role="button" tabindex="0"><div class="dumoDb YkW4Kb" data-processed="true"></div></div></div></div><div data-processed="true" id="bkmrk-greatstack-youtube-%E2%80%A2-1">[<div class="RhEuY" data-processed="true"><div class="SWvopd" data-processed="true" jscontroller="aNJZAb" jsuid="zUVu8b_8a"><div class="Lki2rc" data-processed="true"></div><div class="JccCTc xG6cCf" data-processed="true"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="zUVu8b_8c">![](https://articles.ravapps.com/uploads/images/gallery/2025-12/cl8JdB1vuEsWrJON-embedded-image-zrgs4jft.png)</div></div></div><div data-processed="true"><div class="SrjfCd" data-processed="true">GreatStack</div><div class="Pcl3Vd" data-processed="true">YouTube • 9 Oct 2024</div></div></div>](https://www.youtube.com/watch?v=943D7U74_sQ&t=323)</div>

# import { RouterProvider } from "react-router-dom"

<div class="WaaZC" id="bkmrk-"><div class="RJPOee EIJn2" style="animation: none !important;"></div></div><span style="font-size: 13.999999999999998pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">  
</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">import { RouterProvider } from "react-router-dom";</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> statement is used in React applications to import the </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">RouterProvider</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> component from the </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">react-router-dom</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> library.</span>

<span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Functionality of </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">RouterProvider</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">:</span>

<div class="WaaZC" id="bkmrk-provides-the-router-"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CB0QAQ" data-ved="2ahUKEwiUn43LnbCRAxUccWwGHW9UKDwQo_EKegQIHRAB" role="heading">- <span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Provides the Router Context:</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> The </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">RouterProvider</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> component is a core part of React Router v6. It acts as a wrapper for your entire application or the section of your application where routing is managed. It provides the router context to all nested components, allowing them to access routing functionalities like navigation, route matching, and data loading (with v6.4+ data APIs).</span>
- <span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Receives a Router Object:</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> It takes a </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">router</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> prop, which is an object created using one of React Router's router creation functions, such as </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">createBrowserRouter</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> or </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">createHashRouter</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. This router object contains the definition of your application's routes.</span>
- <span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Enables Data APIs:</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> When used with </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">createBrowserRouter</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">RouterProvider</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> enables the use of React Router's data APIs (loaders, actions, fetchers) for efficient data management within your routes.</span>
- <span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Centralized Route Management:</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> By wrapping your application with </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">RouterProvider</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, you centralize the management of your application's routing logic, making it easier to define, organize, and maintain your routes.</span>

</div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CB0QAQ" data-ved="2ahUKEwiUn43LnbCRAxUccWwGHW9UKDwQo_EKegQIHRAB" role="heading">**<span data-huuid="18005257995190196143">Example Usage: </span>**</div></div></div><div class="WaaZC" id="bkmrk-code"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
import React from "react";
import ReactDOM from "react-dom/client";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import App from "./App";
import About from "./About";
import Contact from "./Contact";

const router = createBrowserRouter([
  {
    path: "/",
    element: <App />,
  },
  {
    path: "/about",
    element: <About />,
  },
  {
    path: "/contact",
    element: <Contact />,
  },
]);

ReactDOM.createRoot(document.getElementById("root")).render(
  <React.StrictMode>
    <RouterProvider router={router} />
  </React.StrictMode>
);
```

# import {createBrowserRouter, Navigate} from "react-router-dom";

<span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">This JavaScript line imports </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">createBrowserRouter</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> for setting up application-wide routing and </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Navigate</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> for programmatic redirection within React Router (v6+), allowing you to define routes and easily redirect users based on conditions or actions in your web application. It's used to configure your app's navigation structure and conditionally send users to different pages or paths.   
  
  
</span>

<span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">createBrowserRouter</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">: Setting Up Routes</span>

- <span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Purpose:</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> Creates a history object for typical browser navigation (using the History API) and enables powerful data APIs (loaders, actions).</span>
- <span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Usage:</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> You pass an array of route objects (defining paths and elements to render) to it, then wrap your app with </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">&lt;RouterProvider router={router}&gt;</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. <span class="T286Pc" data-sfc-cp="">.</span><span class="uJ19be notranslate" data-wiz-uids="KaPIT_w,KaPIT_x,KaPIT_y"><span class="vKEkVd" data-animation-atomic=""> </span></span></span>
    
    <div class="Fsg96" data-processed="true" data-sfc-cp="" jsaction="rcuQ6b:&KaPIT_15|npT2md" jscontroller="KHhJQ" jsuid="KaPIT_15">  
    </div>javascript
    
    ```
    import { createBrowserRouter, RouterProvider } from 'react-router-dom';
    import { HomePage } from './pages/HomePage';
    import { AboutPage } from './pages/AboutPage';
    
    const router = createBrowserRouter([
      { path: '/', element: <HomePage /> },
      { path: '/about', element: <AboutPage /> },
    ]);
    
    function App() {
      return <RouterProvider router={router} />;
    }
    
    ```

<span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Navigate</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;">: Programmatic Redirection</span>

- <span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Purpose:</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> A component that renders a &lt;100ms 301 redirect when mounted, useful for authenticated routes or after form submissions.</span>
- <span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Usage:</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;"> Place it inside a component to redirect to a specific </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">to</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> path; use </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">replace</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> to avoid adding to history (e.g., for auth). </span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&KaPIT_1w|npT2md" jscontroller="KHhJQ" jsuid="KaPIT_1w">  
</div><div class="r1PmQe" data-hveid="CAkQAA" data-processed="true" data-wiz-uids="KaPIT_4t,KaPIT_4u,KaPIT_4v" id="bkmrk-javascript" jscontroller="HP6Sjf" jsuid="KaPIT_4s"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">javascript</div></div></div></div>```
import { Navigate } from 'react-router-dom';

function ProtectedRoute({ children }) {
  const isAuthenticated = checkAuthStatus(); // Your auth logic
  if (!isAuthenticated) {
    return <Navigate to="/login" replace />; // Redirect if not logged in
  }
  return children;
}

// In your router:
{ path: '/dashboard', element: <ProtectedRoute><Dashboard /></ProtectedRoute> }

```

# navigate in react router dom

<div class="WaaZC" id="bkmrk-react-router-dom-pro"><div class="rPeykc" data-hveid="CC4QAQ" data-ved="2ahUKEwios9uMn7CRAxU9SGwGHaKfAEIQo_EKegQILhAB"><span data-huuid="2534949350051700693">React Router DOM provides two primary mechanisms for programmatic navigation: the `useNavigate` hook and the `Navigate` component. </span></div><div class="rPeykc" data-hveid="CC4QAQ" data-ved="2ahUKEwios9uMn7CRAxU9SGwGHaKfAEIQo_EKegQILhAB"></div></div><div class="WaaZC" id="bkmrk-1.-usenavigate-hook%3A"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCUQAQ" data-ved="2ahUKEwios9uMn7CRAxU9SGwGHaKfAEIQo_EKegQIJRAB" role="heading">**<span data-huuid="2534949350051698559">1. `useNavigate` Hook: </span>**</div></div><div class="WaaZC" id="bkmrk-the%C2%A0usenavigate-hook"><div class="rPeykc" data-hveid="CCsQAQ" data-ved="2ahUKEwios9uMn7CRAxU9SGwGHaKfAEIQo_EKegQIKxAB"><span data-huuid="2534949350051700521">The `useNavigate` hook is used within functional components to obtain a `navigate` function, which can then be called to programmatically change the route. </span><span data-huuid="2534949350051697406">This is ideal for navigation triggered by events like button clicks, form submissions, or other interactive user actions. </span></div></div><div class="WaaZC" id="bkmrk-code"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div>```
import { useNavigate } from 'react-router-dom';

function MyComponent() {
  const navigate = useNavigate();

  const handleClick = () => {
    navigate('/dashboard'); // Navigates to the /dashboard path
  };

  const handleLoginSuccess = () => {
    navigate('/home', { replace: true }); // Navigates to /home and replaces the current history entry
  };

  const goBack = () => {
    navigate(-1); // Navigates back one step in browser history
  };

  return (
    <button onClick={handleClick}>Go to Dashboard</button>
  );
}
```

<div class="WaaZC" id="bkmrk-2.%C2%A0navigate-componen"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCYQAQ" data-ved="2ahUKEwios9uMn7CRAxU9SGwGHaKfAEIQo_EKegQIJhAB" role="heading"></div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCYQAQ" data-ved="2ahUKEwios9uMn7CRAxU9SGwGHaKfAEIQo_EKegQIJhAB" role="heading">**<span data-huuid="12709365462988987209">2. `Navigate` Component: </span>**</div></div><div class="WaaZC" id="bkmrk-the-navigate-compone"><div class="rPeykc" data-hveid="CCwQAQ" data-ved="2ahUKEwios9uMn7CRAxU9SGwGHaKfAEIQo_EKegQILBAB"><span data-huuid="12709365462988986183">The `Navigate` component is used for declarative navigation, typically for redirects based on certain conditions during the render process. </span><span data-huuid="12709365462988985670">It automatically navigates the user when rendered. </span></div></div><div class="WaaZC" id="bkmrk-code-1"><div class="bsmXxe" id="bkmrk-code-2" role="none"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
import { Navigate } from 'react-router-dom';

function ProtectedRoute({ isAuthenticated }) {
  if (!isAuthenticated) {
    return <Navigate to="/login" replace />; // Redirects to /login if not authenticated
  }
  return <div>Protected content</div>;
}
```

<div class="WaaZC" id="bkmrk-key-differences%3A%C2%A0"><div class="bsmXxe" id="bkmrk-key-differences%3A%C2%A0-1" role="none"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CGIQAQ" data-ved="2ahUKEwios9uMn7CRAxU9SGwGHaKfAEIQo_EKegQIYhAB" role="heading"></div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CGIQAQ" data-ved="2ahUKEwios9uMn7CRAxU9SGwGHaKfAEIQo_EKegQIYhAB" role="heading"></div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CGIQAQ" data-ved="2ahUKEwios9uMn7CRAxU9SGwGHaKfAEIQo_EKegQIYhAB" role="heading">**<span data-huuid="1559139930285727803">Key Differences: </span>**</div></div></div><div class="WaaZC" id="bkmrk-usenavigate-%28imperat"><div class="bsmXxe" id="bkmrk-usenavigate-%28imperat-1" role="none"><div class="bsmXxe" id="bkmrk-usenavigate-%28imperat-2" role="none"><span data-huuid="1559139930285730814">`useNavigate` (Imperative): </span><span data-huuid="1559139930285729087">Used for navigation triggered by events or logic within a function. </span></div><div class="bsmXxe" id="bkmrk-navigate-%28declarativ" role="none"><span data-huuid="1559139930285729729">`Navigate` (Declarative): </span><span data-huuid="1559139930285728002">Used for conditional or automatic navigation during the rendering of a component.</span></div></div></div>

# import { useOutletContext } from "react-router-dom";

<div data-processed="true" data-subtree="aimfl,mfl" id="bkmrk-import-%7B-useoutletco" jscontroller="v48bt" jsuid="tZNiee_9" style="display: contents;">`import { useOutletContext } from "react-router-dom";`</div>imports a React Router hook that lets child route components access data (like state or functions) passed down from a parent route using the `<Outlet context={...} />` prop, avoiding prop drilling and simplifying data sharing in nested routes. This hook provides a convenient way to share dynamic data between parent layouts and their nested content, making it ideal for managing user info, theme settings, or data fetching states across different views.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="tZNiee_c,tZNiee_d,tZNiee_e"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&tZNiee_8|npT2md" jscontroller="zcfIf" jsuid="tZNiee_8">  
</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--1" jsaction="rcuQ6b:&tZNiee_j|npT2md" jscontroller="KHhJQ" jsuid="tZNiee_j">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-how-it-works" jscontroller="a7qCn" jsuid="tZNiee_k" role="heading">**How it works**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--2" jscontroller="a7qCn" jsuid="tZNiee_k" role="heading">  
</div>1. <span class="T286Pc" data-processed="true" data-sfc-cp="">**Parent Route (e.g., `DashboardLayout.js`)**: Renders the `<Outlet>` component and passes data to its `context` prop.  
      
    </span>```
    import { Outlet } from 'react-router-dom';
    function DashboardLayout() {
      const [user, setUser] = React.useState({ name: 'Alice' });
      return (
        <div>
          <h1>Dashboard</h1>
          {/* Pass data (or state/setters) through context */}
          <Outlet context={{ user, setUser }} />
        </div>
      );
    }
    
    ```
2. <span class="T286Pc" data-processed="true" data-sfc-cp="">**Child Route (e.g., `Profile.js`)**: Uses `useOutletContext()` to get the passed data.</span><div class="r1PmQe" data-hveid="CAMQBA" data-processed="true" data-wiz-uids="tZNiee_17,tZNiee_18,tZNiee_19" jscontroller="HP6Sjf" jsuid="tZNiee_16"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">  
    </div></div></div></div>

```
import { useOutletContext } from 'react-router-dom';
function Profile() {
  // Destructure data from the context
  const { user, setUser } = useOutletContext();
  return (
    <div>
      <p>Welcome, {user.name}</p>
      <button onClick={() => setUser({ name: 'Bob' })}>Change User</button>
    </div>
  );
}

```

<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="tZNiee_1c,tZNiee_1d,tZNiee_1e"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--3" jsaction="rcuQ6b:&tZNiee_1f|npT2md" jscontroller="KHhJQ" jsuid="tZNiee_1f">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-key-benefits" jscontroller="a7qCn" jsuid="tZNiee_1g" role="heading">**Key benefits**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--4" jscontroller="a7qCn" jsuid="tZNiee_1g" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Avoids Prop Drilling**: Data is accessible to any nested component without passing it through every intermediate component.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Centralized Data**: Parent routes manage state or data needed by multiple children.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**TypeScript Friendly**: Can be easily typed for better development experience</span>

# Vite

# import { defineConfig } from 'vite'

<div class="WaaZC" id="bkmrk-the-line-import-%7B-de"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CAUQAQ" data-ved="2ahUKEwizxJnHoLCRAxViUGcHHQnLFoQQo_EKegQIBRAB"><span data-huuid="7591640550378436054">The line `import { defineConfig } from 'vite'` is a standard import statement used in JavaScript and TypeScript projects that utilize Vite as their build tool. </span></div><div class="rPeykc" data-hveid="CAUQAQ" data-ved="2ahUKEwizxJnHoLCRAxViUGcHHQnLFoQQo_EKegQIBRAB"></div></div></div><div class="WaaZC" id="bkmrk-purpose%3A"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CAMQAQ" data-ved="2ahUKEwizxJnHoLCRAxViUGcHHQnLFoQQo_EKegQIAxAB" role="heading">**<span data-huuid="7591640550378438448">Purpose: </span>**</div></div></div><div class="WaaZC" id="bkmrk-importing-defineconf"><div class="RJPOee EIJn2" style="animation: none !important;">- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="7591640550378437943">Importing `defineConfig`: </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="7591640550378435044">This statement imports the `defineConfig` helper function from the `vite` package. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="7591640550378437438">**Providing Intellisense and Type Checking:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="7591640550378438635">The primary purpose of `defineConfig` is to provide type hints and better Intellisense support within your IDE when configuring Vite. </span><span data-huuid="7591640550378435736">By wrapping your Vite configuration object with `defineConfig`, you benefit from autocompletion and type checking, which helps prevent errors and ensures your configuration adheres to Vite's expected structure. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="7591640550378438130">**Defining Vite Configuration:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="7591640550378435231">This function is typically used in the `vite.config.js` (or `vite.config.ts`) file, which is the central place to define your project's build and development settings for Vite. </span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-example-usage%3A"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CBcQAQ" data-ved="2ahUKEwizxJnHoLCRAxViUGcHHQnLFoQQo_EKegQIFxAB" role="heading">**<span data-huuid="13781723138190841278">Example Usage: </span>**</div></div></div><div class="WaaZC" id="bkmrk-"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">  
</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
// vite.config.js
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    // your Vite plugins here, e.g., @vitejs/plugin-react
  ],
  server: {
    port: 3000,
  },
  build: {
    outDir: 'dist',
  },
});
```

<div class="WaaZC" id="bkmrk-in-this-example%2C-the"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CBsQAQ" data-ved="2ahUKEwizxJnHoLCRAxViUGcHHQnLFoQQo_EKegQIGxAB"><span data-huuid="17957175148721145227">In this example, the configuration object passed to `defineConfig` specifies various Vite settings, including plugins, server options, and build options. </span><span data-huuid="17957175148721144338">The `defineConfig` wrapper helps ensure that these settings are correctly typed and recognized by your app.</span></div></div><div class="rPeykc" data-hveid="CBsQAQ" data-ved="2ahUKEwizxJnHoLCRAxViUGcHHQnLFoQQo_EKegQIGxAB"></div></div><div class="rPeykc" data-hveid="CBsQAQ" data-ved="2ahUKEwizxJnHoLCRAxViUGcHHQnLFoQQo_EKegQIGxAB" id="bkmrk--1"></div><div class="rPeykc" data-hveid="CBsQAQ" data-ved="2ahUKEwizxJnHoLCRAxViUGcHHQnLFoQQo_EKegQIGxAB" id="bkmrk-key-parameters-in-de"><span data-huuid="17957175148721144338">**Key Parameters in** `<strong>defineConfig</strong>`</span><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" jscontroller="a7qCn" jsuid="V9GUte_r" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`plugins`**: Array of Vite plugins (e.g., React, Vue, TS Paths) to add functionality.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`server`**: Options for the development server (e.g., `port`, `host`, `open`, `proxy`).</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`build`**: Settings for the production build (e.g., `outDir`, `minify`, `target`).</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`resolve`**: Path aliases (e.g., `@/src`) and module resolution settings.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`define`**: Global constants (e.g., `__APP_VERSION__`) that get replaced during build.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`envDir` / `envPrefix`**: Control where `.env` files are loaded and which variables are exposed.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`base`**: Public path for assets (e.g., `/my-app/`).</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="V9GUte_21,V9GUte_22,V9GUte_23"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" jsaction="rcuQ6b:&V9GUte_2c|npT2md" jscontroller="KHhJQ" jsuid="V9GUte_2c">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" jscontroller="a7qCn" jsuid="V9GUte_2d" role="heading">**Advanced Usage**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" jscontroller="a7qCn" jsuid="V9GUte_2d" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Conditional Config**: Export a function from `defineConfig` to set options based on `command` (dev/build) or `mode` (development/production).</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Rollup Options**: Use `build.rollupOptions` to deeply customize Rollup (e.g., `output.entryFileNames`, `external` modules)</span>

</div><div class="WaaZC" id="bkmrk-development-environm"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CBsQAQ" data-ved="2ahUKEwizxJnHoLCRAxViUGcHHQnLFoQQo_EKegQIGxAB"></div><div class="rPeykc" data-hveid="CBsQAQ" data-ved="2ahUKEwizxJnHoLCRAxViUGcHHQnLFoQQo_EKegQIGxAB"><span data-huuid="17957175148721144338">development environment.</span></div></div></div>

# @vitejs/plugin-react

`@vitejs/plugin-react` is the official Vite plugin for React and React Server Components, providing fast development with HMR (Hot Module Replacement), asset handling (images, CSS), JSX/TSX support, and optimizing builds with options like using [SWC](https://www.google.com/search?client=ubuntu-sn&channel=fs&q=SWC&mstk=AUtExfB2qGCwQD7X2OGQzjRfSPtf1MVkgqlyQERK2bIlAQrdNs1EG_R8iksQMEPuvYQIzB7NFQzAUxEp6qHSEH_ChHR3qCftRqo-hfOUrlcdwQZwJiM5j14s-UCDfN1kzylLeF-hN9kbeLwBRq_7IdCeQeH_iEDOd4Kq2xn3nu6Pg1v5S2F6bkOgwPezGZ7kESq9cHJDI1N6TuvC7c3YNQRQhvLUicDPkAsZ3qKIv6hjH46Dcvucf7Tf8MyzF0gMlSfdrh23w0tbSjczNYxKe9ZFBtqg&csui=3&ved=2ahUKEwje5ar3n7CRAxWTRWcHHX8mCeYQgK4QegQIARAD) for speed, enabling features like React Refresh and TypeScript decorators, making React development in Vite super efficient.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="ph8Ky_g,ph8Ky_h,ph8Ky_i"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&ph8Ky_8|npT2md" jscontroller="zcfIf" jsuid="ph8Ky_8">  
</div><div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk--1" jsaction="rcuQ6b:&ph8Ky_8|npT2md" jscontroller="zcfIf" jsuid="ph8Ky_8"></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--2" jsaction="rcuQ6b:&ph8Ky_o|npT2md" jscontroller="KHhJQ" jsuid="ph8Ky_o">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-key-features-%26-benef" jscontroller="a7qCn" jsuid="ph8Ky_p" role="heading">**Key Features &amp; Benefits:**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--3" jscontroller="a7qCn" jsuid="ph8Ky_p" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Fast Dev Server:** Blazing fast starts and instant HMR with React components and MDX.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**[JSX/TSX](https://www.google.com/search?client=ubuntu-sn&channel=fs&q=JSX%2FTSX&mstk=AUtExfB2qGCwQD7X2OGQzjRfSPtf1MVkgqlyQERK2bIlAQrdNs1EG_R8iksQMEPuvYQIzB7NFQzAUxEp6qHSEH_ChHR3qCftRqo-hfOUrlcdwQZwJiM5j14s-UCDfN1kzylLeF-hN9kbeLwBRq_7IdCeQeH_iEDOd4Kq2xn3nu6Pg1v5S2F6bkOgwPezGZ7kESq9cHJDI1N6TuvC7c3YNQRQhvLUicDPkAsZ3qKIv6hjH46Dcvucf7Tf8MyzF0gMlSfdrh23w0tbSjczNYxKe9ZFBtqg&csui=3&ved=2ahUKEwje5ar3n7CRAxWTRWcHHX8mCeYQgK4QegQIAxAC) Support:** Handles React syntax (JSX/TSX) for seamless development.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Asset Handling:** Imports images, CSS, etc., directly into components.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**React Refresh (HMR):** See changes instantly without full page reloads.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**SWC [ Option](https://www.google.com/search?client=ubuntu-sn&channel=fs&q=Option&mstk=AUtExfB2qGCwQD7X2OGQzjRfSPtf1MVkgqlyQERK2bIlAQrdNs1EG_R8iksQMEPuvYQIzB7NFQzAUxEp6qHSEH_ChHR3qCftRqo-hfOUrlcdwQZwJiM5j14s-UCDfN1kzylLeF-hN9kbeLwBRq_7IdCeQeH_iEDOd4Kq2xn3nu6Pg1v5S2F6bkOgwPezGZ7kESq9cHJDI1N6TuvC7c3YNQRQhvLUicDPkAsZ3qKIv6hjH46Dcvucf7Tf8MyzF0gMlSfdrh23w0tbSjczNYxKe9ZFBtqg&csui=3&ved=2ahUKEwje5ar3n7CRAxWTRWcHHX8mCeYQgK4QegQIAxAG)**: Use the faster SWC compiler via `@vitejs/plugin-react-swc` for quicker builds.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**React Server Components (RSC):** Supports building apps with RSCs via `@vitejs/plugin-rsc`.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Build Optimization:** Code splitting and efficient bundling for production.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="ph8Ky_1j,ph8Ky_1k,ph8Ky_1l"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--4" jsaction="rcuQ6b:&ph8Ky_1r|npT2md" jscontroller="KHhJQ" jsuid="ph8Ky_1r">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-how-it-works-with-vi" jscontroller="a7qCn" jsuid="ph8Ky_1s" role="heading">**How it works with Vite:**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--5" jscontroller="a7qCn" jsuid="ph8Ky_1s" role="heading">  
</div>1. <span class="T286Pc" data-processed="true" data-sfc-cp="">**Installation:** You install it (often automatically when you scaffold a React project with Vite).</span>
2. <span class="T286Pc" data-processed="true" data-sfc-cp="">**Configuration:** It's configured in `vite.config.js` (or `.ts`).</span>
3. <span class="T286Pc" data-processed="true" data-sfc-cp="">**Development:** Vite's dev server uses the plugin to process React code quickly.</span>
4. <span class="T286Pc" data-processed="true" data-sfc-cp="">**Build:** The plugin prepares your React app for production.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="ph8Ky_2b,ph8Ky_2c,ph8Ky_2d"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAYQAA" data-processed="true" data-sfc-cp="" id="bkmrk-in-short%2C-it%27s-the-e" jsaction="rcuQ6b:&ph8Ky_2h|npT2md" jscontroller="zcfIf" jsuid="ph8Ky_2h">In short, it's the essential bridge that brings the power and speed of Vite to your React projects.</div>

# vite package different components

<div class="WaaZC" id="bkmrk-vite%27s-%22library-mode"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CAUQAQ" data-ved="2ahUKEwjRpZXaoLCRAxUDcGwGHQXbIVMQo_EKegQIBRAB"><span data-huuid="3562406143257101670">Vite's "library mode" is the primary method for packaging different components or a component library for distribution as an NPM package. </span><span data-huuid="3562406143257101485">This allows you to build your components into optimized bundles that can be easily consumed by other projects. </span></div></div></div><div class="WaaZC" id="bkmrk-here%27s-a-breakdown-o"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc uP58nb" data-hveid="CAIQAQ" data-ved="2ahUKEwjRpZXaoLCRAxUDcGwGHQXbIVMQo_EKegQIAhAB"><span data-huuid="3562406143257101115"><span aria-level="2" role="heading">Here's a breakdown of the key steps and concepts involved:</span> </span></div></div><div class="rPeykc uP58nb" data-hveid="CAIQAQ" data-ved="2ahUKEwjRpZXaoLCRAxUDcGwGHQXbIVMQo_EKegQIAhAB"></div></div><div class="WaaZC" id="bkmrk-project-setup%3A-initi"><div class="RJPOee EIJn2" style="animation: none !important;">- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="3562406143257100560">**Project Setup:** </span></div><div class="vM0jzc" style="display: inline;">
    - <span data-huuid="3562406143257104101">Initialize a new Vite project or use an existing one. </span>
    - <span data-huuid="3562406143257103731">Ensure your project structure clearly separates your library components (e.g., in a `lib` folder) from any demo or development-only code (e.g., in a `src` folder). </span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;">**<span data-huuid="3562406143257103361">Vite Configuration (`vite.config.js`): </span>**</div><div class="vM0jzc" style="display: inline;">
    - <span data-huuid="3562406143257102806">`build.lib`: </span><span data-huuid="3562406143257102621">This is the core of library mode. </span><span data-huuid="3562406143257102436">You define the entry point of your library and the output formats. </span>
        - <span data-huuid="3562406143257101881">`entry`: Path to your main library file (e.g., `lib/main.js` or `lib/index.ts`). </span>
        - <span data-huuid="3562406143257101511">`name`: The global variable name for your library when used in UMD format. </span>
        - <span data-huuid="3562406143257101141">`fileName`: The name of the output bundle file(s). </span><span data-huuid="3562406143257100956">You can use a function to customize file names based on format and entry name. </span>
    - <span data-huuid="3562406143257100586">`build.rollupOptions`: </span><span data-huuid="3562406143257100401">Customize Rollup's behavior (the underlying bundler Vite uses). </span>
        - <span data-huuid="3562406143257103942">`external`: Define dependencies that should not be bundled into your library (e.g., `react`, `vue`). </span><span data-huuid="3562406143257103757">These will be treated as external dependencies that the consuming project needs to provide. </span>
        - <span data-huuid="3562406143257103387">`output.globals`: Map external dependencies to their global variable names for UMD builds. </span>
    - 
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="3562406143257103017">**Component Implementation:** </span></div><div class="vM0jzc" style="display: inline;">
    - <span data-huuid="3562406143257102462">Create your components within your designated library folder. </span>
    - <span data-huuid="3562406143257102092">Use standard ES module `export` statements to make your components available for import. </span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="3562406143257101722">**Type Definitions (Optional but Recommended):** </span></div><div class="vM0jzc" style="display: inline;">
    - <span data-huuid="3562406143257101167">If you're using TypeScript, generate type definitions (`.d.ts` files) for your library. </span><span data-huuid="3562406143257100982">Plugins like `vite-plugin-dts` can automate this process. </span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="3562406143257100612">**Building the Library:** </span></div><div class="vM0jzc" style="display: inline;">
    - <span data-huuid="3562406143257104153">Run the Vite build command, which will generate the bundled output in your `dist` folder according to your `vite.config.js` settings. </span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="3562406143257103783">**Publishing (for NPM Packages):** </span></div><div class="vM0jzc" style="display: inline;">
    - <span data-huuid="3562406143257103228">Ensure your `package.json` correctly defines your package name, version, main entry points (e.g., `main`, `module`, `types`), and any necessary dependencies. </span>
    - <span data-huuid="3562406143257102858">Publish your package to NPM. </span>
    
    </div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-example-vite.config."><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CEYQAQ" data-ved="2ahUKEwjRpZXaoLCRAxUDcGwGHQXbIVMQo_EKegQIRhAB" role="heading">**<span data-huuid="4061063841968288043">Example `vite.config.js` snippet for a component library: </span>**</div></div></div><div class="WaaZC" id="bkmrk-"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod">  
<div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [react()],
  build: {
    lib: {
      entry: 'lib/main.js', // Your library's entry point
      name: 'MyComponentLibrary', // Global variable name for UMD
      fileName: (format) => `my-component-library.${format}.js`,
    },
    rollupOptions: {
      external: ['react', 'react-dom'], // Exclude React from the bundle
      output: {
        globals: {
          react: 'React',
          'react-dom': 'ReactDOM',
        },
      },
    },
  },
});
```

# React DOM Package

# import ReactDOM from 'react-dom/client'

<div class="WaaZC" id="bkmrk-the-statement-import"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CAUQAQ" data-ved="2ahUKEwimwPr8nLCRAxXSU2wGHcWXErgQo_EKegQIBRAB"><span data-huuid="16003904160212444154">The statement `import ReactDOM from 'react-dom/client'` is used in React applications, specifically starting from React 18, to import the client-side rendering capabilities of ReactDOM. </span></div><div class="rPeykc" data-hveid="CAUQAQ" data-ved="2ahUKEwimwPr8nLCRAxXSU2wGHcWXErgQo_EKegQIBRAB"></div></div></div><div class="WaaZC" id="bkmrk-explanation%3A"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CAMQAQ" data-ved="2ahUKEwimwPr8nLCRAxXSU2wGHcWXErgQo_EKegQIAxAB" role="heading">**<span data-huuid="16003904160212443660">Explanation: </span>**</div></div></div><div class="WaaZC" id="bkmrk-reactdom%3A-this-refer"><div class="RJPOee EIJn2" style="animation: none !important;">- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="16003904160212444967">`ReactDOM`: </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="16003904160212446768">This refers to the core React package that provides methods for interacting with the Document Object Model (DOM). </span><span data-huuid="16003904160212444473">It's responsible for rendering React components into the browser's DOM. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="16003904160212443979">`'react-dom/client'`: </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="16003904160212445780">This specific import path indicates that you are importing the client-specific methods of ReactDOM. </span><span data-huuid="16003904160212443485">In earlier versions of React (prior to React 18), you would typically import `ReactDOM` directly from `'react-dom'`. </span><span data-huuid="16003904160212445286">However, with the introduction of React 18 and its concurrent features, the client-side rendering functionalities were separated into a dedicated `'react-dom/client'` module. </span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-key-functions-you-wo"><div class="RJPOee EIJn2" style="animation: none !important;"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CBUQAQ" data-ved="2ahUKEwimwPr8nLCRAxXSU2wGHcWXErgQo_EKegQIFRAB" role="heading">**<span data-huuid="246065413123630172">Key functions you would typically use after this import: </span>**</div></div></div><div class="WaaZC" id="bkmrk-createroot%28container"><div class="RJPOee EIJn2" style="animation: none !important;">- <span data-huuid="246065413123629431">`createRoot(container[, options])`: </span><span data-huuid="246065413123629184">This function is used to create a React root for a given DOM element (`container`). </span><span data-huuid="246065413123633033">It returns a root object that you can then use to render your React application. </span>

</div></div>```
  import ReactDOM from 'react-dom/client';

  const root = ReactDOM.createRoot(document.getElementById('root'));
  root.render(
    // Your React components here
  );
```

<div class="WaaZC" id="bkmrk-hydrateroot%28containe"><div class="RJPOee EIJn2" style="animation: none !important;">- <span data-huuid="2808456318680487087">`hydrateRoot(container, element[, options])`: </span><span data-huuid="2808456318680487674">This function is used for hydrating server-rendered HTML. </span><span data-huuid="2808456318680488261">If you are using server-side rendering (SSR), `hydrateRoot` is used on the client to attach event listeners and make the server-rendered HTML interactive. </span>

</div></div><div class="WaaZC" id="bkmrk-in-essence%2C-import-r"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CCYQAQ" data-ved="2ahUKEwimwPr8nLCRAxXSU2wGHcWXErgQo_EKegQIJhAB"><span data-huuid="3842530573012008287">In essence, `import ReactDOM from 'react-dom/client'` is the modern way to set up client-side rendering in React 18 and later, providing access to the `createRoot` and `hydrateRoot` functions for managing your React application's lifecycle in the browser</span></div></div></div>

# package react-dom/client

<div class="WaaZC" id="bkmrk-the-react-dom%2Fclient"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CAYQAQ" data-ved="2ahUKEwjeyYeYnbCRAxUsR2wGHV0oGboQo_EKegQIBhAB"><span data-huuid="2230162411706762478">The `react-dom/client` package in React provides client-specific methods for initializing and managing a React application within a browser environment. </span><span data-huuid="2230162411706762991">This package is specifically designed for rendering and interacting with the Document Object Model (DOM) on the client side. </span></div></div><div class="rPeykc" data-hveid="CAYQAQ" data-ved="2ahUKEwjeyYeYnbCRAxUsR2wGHV0oGboQo_EKegQIBhAB"></div></div><div class="WaaZC" id="bkmrk-key-functionalities-"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc uP58nb" data-hveid="CAMQAQ" data-ved="2ahUKEwjeyYeYnbCRAxUsR2wGHV0oGboQo_EKegQIAxAB">**<span data-huuid="2230162411706764017"><span aria-level="2" role="heading">Key functionalities provided by `react-dom/client` include:</span> </span>**</div></div></div><div class="WaaZC" id="bkmrk-createroot%28%29%3A-this-f"><div class="RJPOee EIJn2" style="animation: none !important;">- <span data-huuid="2230162411706761460">`createRoot()`: </span><span data-huuid="2230162411706761973">This function is the entry point for creating a root for your React application in React 18 and later. </span><span data-huuid="2230162411706762486">It takes a DOM element as an argument and returns a root object, which you then use to render your React components. </span>

</div></div><div class="WaaZC" id="bkmrk-"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div aria-live="polite" class="WDoJJe"></div></div></div></div></div></div></div></div>```
    import { createRoot } from 'react-dom/client';
    const container = document.getElementById('root');
    const root = createRoot(container);
    root.render(<App />);
```

<div class="WaaZC" id="bkmrk-hydrateroot%28%29%3A-this-"><div class="RJPOee EIJn2" style="animation: none !important;">- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="6999054211660591134">`hydrateRoot()`: </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="6999054211660591443">This function is used for hydrating a server-side rendered (SSR) React application on the client. </span><span data-huuid="6999054211660591752">It takes the server-generated HTML and attaches event handlers and state, making the application interactive. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="6999054211660592370">`root.render()`: </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="6999054211660592679">A method of the root object returned by `createRoot()`, used to render a React element into the DOM. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="6999054211660593297">`root.unmount()`: </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="6999054211660593606">A method of the root object returned by `createRoot()`, used to unmount a React component from the DOM. </span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-in-essence%2C-react-do"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CB8QAQ" data-ved="2ahUKEwjeyYeYnbCRAxUsR2wGHV0oGboQo_EKegQIHxAB"><span data-huuid="18282434738024879722">In essence, `react-dom/client` is the bridge between your React components and the browser's DOM, enabling the rendering, updating, and management of your application's user interface on the client side. </span><span data-huuid="18282434738024881075">It's the modern way to handle client-side rendering in React, especially with the introduction of React 18's new concurrent feature</span></div></div></div>

# @types/react-dom

<div data-processed="true" data-subtree="aimfl,mfl" id="bkmrk-%40types%2Freact-dom" jscontroller="v48bt" jsuid="JY9r6_9" style="display: contents;">`@types/react-dom`</div>is <mark class="HxTRcb" data-processed="true">a TypeScript definition package from the DefinitelyTyped project that provides type information for the [react-dom](https://www.google.com/search?client=ubuntu-sn&channel=fs&q=react-dom&mstk=AUtExfD0el60w1UFWrdjeaK66vjv8Sx85mg1MsIt7NfrYdqoGPsoINnouUlHZXMXzYJQEYwcs4ZHYmlczfkbRKxI1XWIZgAYzCpG8HQR-8uHsIHiOxQSbnUf6iITch5hQoIELCJlu0xFkG1XQJ2diJ_bUazfnDYrxiZP_Ji8VR--TAzslrvM-A7501A9j-6CtrNQpv8EsN68T8XVWgwlHOVP6O0NFbNaODrv2nwKY6IwBMjfZ1V4Hdz5AxkN5d4_e0TFbLVW1EbcEnjMa1PKlnUXQMB0&csui=3&ved=2ahUKEwiYsdP-n7CRAxX5S2wGHawMMCQQgK4QegQIARAC) library</mark>, essential for building React apps with TypeScript to get autocompletion and type safety for DOM-specific React functions like `ReactDOM.render()` and server-side rendering methods, installed via npm or yarn alongside `react` and `@types/react`.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="JY9r6_g,JY9r6_h,JY9r6_i"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&JY9r6_8|npT2md" jscontroller="zcfIf" jsuid="JY9r6_8">  
</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--1" jsaction="rcuQ6b:&JY9r6_m|npT2md" jscontroller="KHhJQ" jsuid="JY9r6_m">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-purpose-%26-use" jscontroller="a7qCn" jsuid="JY9r6_n" role="heading">**Purpose &amp; Use**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--2" jscontroller="a7qCn" jsuid="JY9r6_n" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Type Definitions**: Adds static types for `react-dom`, allowing TypeScript to understand functions, properties, and return types for DOM manipulation within React.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**TypeScript Integration**: Crucial for TypeScript projects using React, providing IntelliSense and error checking for `react-dom` APIs.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Server-Side Rendering (SSR)**: Includes types for `ReactDOMServer` for SSR scenarios.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="JY9r6_14,JY9r6_15,JY9r6_16"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--3" jsaction="rcuQ6b:&JY9r6_1a|npT2md" jscontroller="KHhJQ" jsuid="JY9r6_1a">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-installation" jscontroller="a7qCn" jsuid="JY9r6_1b" role="heading">**Installation**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--4" jscontroller="a7qCn" jsuid="JY9r6_1b" role="heading">  
</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--5" jsaction="rcuQ6b:&JY9r6_1f|npT2md" jscontroller="KHhJQ" jsuid="JY9r6_1f">  
</div><div class="r1PmQe" data-hveid="CAUQAA" data-processed="true" data-wiz-uids="JY9r6_1h,JY9r6_1i,JY9r6_1j" id="bkmrk-bash" jscontroller="HP6Sjf" jsuid="JY9r6_1g"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">bash</div></div></div></div>```
npm install --save-dev @types/react @types/react-dom
# or
yarn add -D @types/react @types/react-dom

```

<div class="Y3BBE" data-hveid="CAYQAA" data-processed="true" data-sfc-cp="" id="bkmrk-note%3A-you%27ll-typical" jsaction="rcuQ6b:&JY9r6_1m|npT2md" jscontroller="zcfIf" jsuid="JY9r6_1m">*Note: You'll typically install `@types/react` and `@types/react-dom` together for a full setup.*<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="JY9r6_1q,JY9r6_1r,JY9r6_1s"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span></div><div class="Y3BBE" data-hveid="CAYQAA" data-processed="true" data-sfc-cp="" id="bkmrk--6" jsaction="rcuQ6b:&JY9r6_1m|npT2md" jscontroller="zcfIf" jsuid="JY9r6_1m">  
</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--7" jsaction="rcuQ6b:&JY9r6_1u|npT2md" jscontroller="KHhJQ" jsuid="JY9r6_1u">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-key-exports" jscontroller="a7qCn" jsuid="JY9r6_1v" role="heading">**Key Exports**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--8" jscontroller="a7qCn" jsuid="JY9r6_1v" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">`ReactDOM`: For client-side rendering (e.g., `ReactDOM.createRoot()`).</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">`ReactDOMServer`: For server-side rendering (e.g., `ReactDOMServer.renderToString()`).</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="JY9r6_28,JY9r6_29,JY9r6_2a"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--9" jsaction="rcuQ6b:&JY9r6_2d|npT2md" jscontroller="KHhJQ" jsuid="JY9r6_2d">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-how-it-works" jscontroller="a7qCn" jsuid="JY9r6_2e" role="heading">**How it Works**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--10" jscontroller="a7qCn" jsuid="JY9r6_2e" role="heading">  
</div><div class="Y3BBE" data-hveid="CAoQAA" data-processed="true" data-sfc-cp="" id="bkmrk-when-you-use-react-w" jsaction="rcuQ6b:&JY9r6_2i|npT2md" jscontroller="zcfIf" jsuid="JY9r6_2i">When you use React with TypeScript, `@types/react-dom` (and `@types/react`) provides the "contracts" for how these libraries work, ensuring you're using them correctly and catching potential bugs before runtime</div>

# react-dom

<div class="WaaZC" id="bkmrk-react-dom-is-a-core-"><div class="rPeykc" data-hveid="CDcQAQ" data-ved="2ahUKEwjwvq6qoLCRAxVqTmwGHV5YGHgQo_EKegQINxAB"><span data-huuid="15962349409372647396">`react-dom` is a core package within the React ecosystem, specifically designed for web applications that run in the browser's Document Object Model (DOM) environment. </span><span data-huuid="15962349409372647177">It provides the necessary methods and functionalities to interact with and manipulate the DOM, enabling React to efficiently render and manage web page elements. </span></div></div><div class="rPeykc" data-hveid="CDcQAQ" data-ved="2ahUKEwjwvq6qoLCRAxVqTmwGHV5YGHgQo_EKegQINxAB" id="bkmrk-"></div><div class="rPeykc" data-hveid="CDcQAQ" data-ved="2ahUKEwjwvq6qoLCRAxVqTmwGHV5YGHgQo_EKegQINxAB" id="bkmrk--1"></div><div class="WaaZC" id="bkmrk--2"><div class="rPeykc" data-hveid="CDcQAQ" data-ved="2ahUKEwjwvq6qoLCRAxVqTmwGHV5YGHgQo_EKegQINxAB">  
</div></div><div class="WaaZC" id="bkmrk-key-aspects-of-react"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CC8QAQ" data-ved="2ahUKEwjwvq6qoLCRAxVqTmwGHV5YGHgQo_EKegQILxAB" role="heading">**<span data-huuid="15962349409372646739">Key aspects of `react-dom`: </span>**</div><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CC8QAQ" data-ved="2ahUKEwjwvq6qoLCRAxVqTmwGHV5YGHgQo_EKegQILxAB" role="heading"></div></div><div class="WaaZC" id="bkmrk-dom-specific-methods">- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="15962349409372646082">**DOM-specific methods:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="15962349409372645863">It offers methods like `createRoot` (from `react-dom/client` in React 18+) for initializing a React application by attaching it to a root DOM element, and `render` (used on the `root` object) to render React elements into the DOM. </span></div></div></div></div>

<div class="bsmXxe" id="bkmrk-client-apis%3A-the-rea" role="none"><div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;">- <span data-huuid="15962349409372645425">**Client APIs:** </span><div class="vM0jzc" style="display: inline;"><span data-huuid="15962349409372645206">The `react-dom/client` module contains APIs primarily used at the top level of a client-side React application to render components in the browser. </span></div>

</div></div></div></div></div><div class="bsmXxe" id="bkmrk-server-apis%3A-the-rea" role="none"><div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;">- <span data-huuid="15962349409372644768">**Server APIs:** </span><div class="vM0jzc" style="display: inline;"><span data-huuid="15962349409372644549">The `react-dom/server` module provides APIs for rendering React components to HTML strings on the server, a common practice in server-side rendering (SSR) for improved performance and SEO. </span></div>

</div></div></div></div></div><div class="bsmXxe" id="bkmrk-hooks-and-components" role="none"><div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;">- <span data-huuid="15962349409372644111">**Hooks and Components:** </span><div class="vM0jzc" style="display: inline;"><span data-huuid="15962349409372643892">`react-dom` also includes Hooks and components specifically tailored for web applications, such as those related to managing focus, scroll position, or interacting with browser APIs. </span></div>

</div></div></div></div></div><div class="bsmXxe" id="bkmrk-dom-manipulation%3A-wh" role="none"><div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;">- <span data-huuid="15962349409372643454">**DOM Manipulation:** </span><div class="vM0jzc" style="display: inline;"><span data-huuid="15962349409372647331">While React encourages working with its declarative component model, `react-dom` offers escape hatches like `useRef` that allow direct manipulation of the DOM when necessary, for example, to integrate with third-party libraries or handle specific browser interactions. </span></div>

</div></div></div></div></div><div class="bsmXxe" id="bkmrk-hydration%3A-react-dom" role="none"><div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;">- <span data-huuid="15962349409372646893">**Hydration:** </span><div class="vM0jzc" style="display: inline;"><span data-huuid="15962349409372646674">`react-dom` facilitates hydration, the process of attaching event listeners and making a server-rendered HTML page interactive on the client-side. </span></div>

</div></div></div></div></div></div><div class="WaaZC" id="bkmrk-in-essence%2C-react-do"><div class="bsmXxe" id="bkmrk-in-essence%2C-react-do-1" role="none"><div class="rPeykc" data-hveid="CHkQAQ" data-ved="2ahUKEwjwvq6qoLCRAxVqTmwGHV5YGHgQo_EKegQIeRAB"><span data-huuid="9463616492079696546">In essence, `react-dom` serves as the bridge between your React components and the actual web page displayed in the browser, handling the intricate details of DOM management so you can focus on building your application's UI with React's declarative paradigm</span></div></div></div>

# Axios

# Axios in React

Axios in React simplifies HTTP requests using a promise-based API for methods like `get`, `post`, `put`, `delete`, and `patch`, offering features like <mark class="HxTRcb" data-processed="true">automatic JSON transformation, request/response interception, cancellation, timeout settings, and built-in error handling</mark> (rejecting on 4xx/5xx status codes). Key properties include `response.data` for payload, `error.response` for detailed HTTP errors, `config` for settings (headers, timeouts), and `axios.create()` for custom instances, making API communication clean and efficient in React apps.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="ci3AU_o,ci3AU_p,ci3AU_q"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&ci3AU_8|npT2md" jscontroller="zcfIf" jsuid="ci3AU_8">  
</div><div class="Y3BBE" data-hveid="CAIQAA" data-processed="true" data-sfc-cp="" id="bkmrk-this-video-provides-" jsaction="rcuQ6b:&ci3AU_w|npT2md" jscontroller="zcfIf" jsuid="ci3AU_w">This video provides a tutorial on making API requests with Axios in React: <div class="" data-processed="true" data-wiz-uids="ci3AU_y,ci3AU_z" jscontroller="uDeH3" jsuid="ci3AU_x"><div data-hveid="CAIQAQ" data-processed="true" data-ved="2ahUKEwjx_KHqn7CRAxU0SGwGHaCRLPIQ-bUQegQIAhAB"><div data-processed="true"><div class="Q2WBBe" data-processed="true" jsuid="ci3AU_z"><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwjx_KHqn7CRAxU0SGwGHaCRLPIQypYSegQIAhAC" jsuid="ci3AU_y" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="ci3AU_11" jsaction="rcuQ6b:&ci3AU_10|npT2md" jscallback="gfNXHe:&ci3AU_x:U8wGUb" jscontroller="wMmv4c" jsuid="ci3AU_10"><div class="nrdPJf" data-processed="true" data-ved="2ahUKEwjx_KHqn7CRAxU0SGwGHaCRLPIQtbEQegQIAhAD" jsaction="click:&ci3AU_10|T2P31d" jsuid="ci3AU_11" role="button" tabindex="0"><div class="n7j80c YkW4Kb" data-processed="true" jscontroller="ItMuwb" jsuid="ci3AU_12" style="--segment-bar-offset: 12px;"><div class="llCCib" data-processed="true" style="left: 25%;"><svg fill="currentColor" height="12" viewbox="0 0 12 12" width="12" xmlns="http://www.w3.org/2000/svg"></svg></div></div></div></div></div></div></div></div></div></div><div class="n7j80c YkW4Kb" data-processed="true" id="bkmrk--1" jscontroller="ItMuwb" jsuid="ci3AU_12" style="--segment-bar-offset: 12px;"></div><div class="dumoDb YkW4Kb" data-processed="true" id="bkmrk--2"><div class="CaQWce" data-processed="true" jscontroller="sRLmTc" jsuid="ci3AU_13"><svg fill="currentColor" height="18px" viewbox="0 -960 960 960" width="18px" xmlns="http://www.w3.org/2000/svg"></svg></div></div><div class="Y3BBE" data-hveid="CAIQAA" data-processed="true" data-sfc-cp="" id="bkmrk-dave-gray-youtube-%E2%80%A2-" jsaction="rcuQ6b:&ci3AU_w|npT2md" jscontroller="zcfIf" jsuid="ci3AU_w"><div class="" data-processed="true" data-wiz-uids="ci3AU_y,ci3AU_z" jscontroller="uDeH3" jsuid="ci3AU_x"><div data-hveid="CAIQAQ" data-processed="true" data-ved="2ahUKEwjx_KHqn7CRAxU0SGwGHaCRLPIQ-bUQegQIAhAB"><div data-processed="true"><div class="Q2WBBe" data-processed="true" jsuid="ci3AU_z"><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwjx_KHqn7CRAxU0SGwGHaCRLPIQypYSegQIAhAC" jsuid="ci3AU_y" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="ci3AU_11" jsaction="rcuQ6b:&ci3AU_10|npT2md" jscallback="gfNXHe:&ci3AU_x:U8wGUb" jscontroller="wMmv4c" jsuid="ci3AU_10"><div class="nrdPJf" data-processed="true" data-ved="2ahUKEwjx_KHqn7CRAxU0SGwGHaCRLPIQtbEQegQIAhAD" jsaction="click:&ci3AU_10|T2P31d" jsuid="ci3AU_11" role="button" tabindex="0"><div class="dumoDb YkW4Kb" data-processed="true">  
</div></div></div></div><div data-processed="true">[<div class="RhEuY" data-processed="true"><div class="SWvopd" data-processed="true" jscontroller="aNJZAb" jsuid="ci3AU_14"><div class="Lki2rc" data-processed="true"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="ci3AU_15">  
</div></div><div class="JccCTc xG6cCf" data-processed="true"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="ci3AU_16">  
</div></div></div><div data-processed="true"><div class="SrjfCd" data-processed="true">Dave Gray</div><div class="Pcl3Vd" data-processed="true">YouTube • 3 Aug 2021</div></div></div>](https://www.youtube.com/watch?v=ZEKBDXGnD4s&t=549)</div></div></div></div></div></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--3" jsaction="rcuQ6b:&ci3AU_17|npT2md" jscontroller="KHhJQ" jsuid="ci3AU_17">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-key-methods" jscontroller="a7qCn" jsuid="ci3AU_18" role="heading">**Key Methods**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--4" jscontroller="a7qCn" jsuid="ci3AU_18" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`axios(config)`**: The base method, takes a config object for any request type.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`axios.get(url, config)`**: Fetches data from a URL.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`axios.post(url, data, config)`**: Sends data to create a resource.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`axios.put(url, data, config)`**: Updates an existing resource.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`axios.delete(url, config)`**: Deletes a resource.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`axios.patch(url, data, config)`**: Partially updates a resource.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`axios.head(url, config)`**: Gets headers without response body.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`axios.options(url, config)`**: Checks server options.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="ci3AU_29,ci3AU_2a,ci3AU_2b"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--5" jsaction="rcuQ6b:&ci3AU_2d|npT2md" jscontroller="KHhJQ" jsuid="ci3AU_2d">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-core-properties-%26-fe" jscontroller="a7qCn" jsuid="ci3AU_2e" role="heading">**Core Properties &amp; Features**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--6" jscontroller="a7qCn" jsuid="ci3AU_2e" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Promises**: Handles async operations with `.then()` (success) and `.catch()` (error).</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Automatic JSON**: Converts JSON responses to JavaScript objects automatically.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Interceptors**: Modify requests or responses globally before handling (e.g., adding auth tokens).</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Error Handling**: Throws errors for non-2xx status codes (404, 500), unlike Fetch.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Timeouts**: Set `timeout` in config to prevent hanging requests.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Cancellation**: Cancel ongoing requests using `CancelToken` or `AbortController`.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**`axios.create()`**: Creates reusable instances with default configs (base URL, headers).</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="ci3AU_3a,ci3AU_3b,ci3AU_3c"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAcQAA" data-processed="true" data-sfc-cp="" id="bkmrk-this-video-explains-" jsaction="rcuQ6b:&ci3AU_3j|npT2md" jscontroller="zcfIf" jsuid="ci3AU_3j">This video explains how to create custom Axios hooks for your React application: <div class="" data-processed="true" data-wiz-uids="ci3AU_3l,ci3AU_3m" jscontroller="uDeH3" jsuid="ci3AU_3k"><div data-hveid="CAcQAQ" data-processed="true" data-ved="2ahUKEwjx_KHqn7CRAxU0SGwGHaCRLPIQ-bUQegQIBxAB"><div data-processed="true"><div class="Q2WBBe" data-processed="true" jsuid="ci3AU_3m"><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwjx_KHqn7CRAxU0SGwGHaCRLPIQypYSegQIBxAC" jsuid="ci3AU_3l" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="ci3AU_3o" jsaction="rcuQ6b:&ci3AU_3n|npT2md" jscallback="gfNXHe:&ci3AU_3k:U8wGUb" jscontroller="wMmv4c" jsuid="ci3AU_3n"><div class="nrdPJf" data-processed="true" data-ved="2ahUKEwjx_KHqn7CRAxU0SGwGHaCRLPIQtbEQegQIBxAD" jsaction="click:&ci3AU_3n|T2P31d" jsuid="ci3AU_3o" role="button" tabindex="0"><div class="n7j80c YkW4Kb" data-processed="true" jscontroller="ItMuwb" jsuid="ci3AU_3p" style="--segment-bar-offset: 12px;"><div class="llCCib" data-processed="true" style="left: 20%;"><svg fill="currentColor" height="12" viewbox="0 0 12 12" width="12" xmlns="http://www.w3.org/2000/svg"></svg></div></div></div></div></div></div></div></div></div></div><div class="n7j80c YkW4Kb" data-processed="true" id="bkmrk--7" jscontroller="ItMuwb" jsuid="ci3AU_3p" style="--segment-bar-offset: 12px;"></div><div class="Y3BBE" data-hveid="CAcQAA" data-processed="true" data-sfc-cp="" id="bkmrk-code-radiance-youtub" jsaction="rcuQ6b:&ci3AU_3j|npT2md" jscontroller="zcfIf" jsuid="ci3AU_3j"><div class="" data-processed="true" data-wiz-uids="ci3AU_3l,ci3AU_3m" jscontroller="uDeH3" jsuid="ci3AU_3k"><div data-hveid="CAcQAQ" data-processed="true" data-ved="2ahUKEwjx_KHqn7CRAxU0SGwGHaCRLPIQ-bUQegQIBxAB"><div data-processed="true"><div class="Q2WBBe" data-processed="true" jsuid="ci3AU_3m"><div aria-label="" class="r0hyfc" data-animation-nesting="" data-processed="true" data-ved="2ahUKEwjx_KHqn7CRAxU0SGwGHaCRLPIQypYSegQIBxAC" jsuid="ci3AU_3l" tabindex="-1"><div class="RtAO3b" data-processed="true" data-sfc-cp="" data-wiz-uids="ci3AU_3o" jsaction="rcuQ6b:&ci3AU_3n|npT2md" jscallback="gfNXHe:&ci3AU_3k:U8wGUb" jscontroller="wMmv4c" jsuid="ci3AU_3n"><div class="nrdPJf" data-processed="true" data-ved="2ahUKEwjx_KHqn7CRAxU0SGwGHaCRLPIQtbEQegQIBxAD" jsaction="click:&ci3AU_3n|T2P31d" jsuid="ci3AU_3o" role="button" tabindex="0"><div class="dumoDb YkW4Kb" data-processed="true">  
</div></div></div></div><div data-processed="true">[<div class="RhEuY" data-processed="true"><div class="SWvopd" data-processed="true" jscontroller="aNJZAb" jsuid="ci3AU_3r"><div class="Lki2rc" data-processed="true"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="ci3AU_3s">  
</div></div><div class="JccCTc xG6cCf" data-processed="true"><div aria-hidden="true" class="U9BD8 Wsaimf QyEYne" data-processed="true" jscontroller="Cky8Oc" jsuid="ci3AU_3t">  
</div></div></div><div data-processed="true"><div class="SrjfCd" data-processed="true">Code Radiance</div><div class="Pcl3Vd" data-processed="true">YouTube • 11 Feb 2024</div></div></div>](https://www.youtube.com/watch?v=WtijdoNfzYg&t=166)</div></div></div></div></div></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--8" jsaction="rcuQ6b:&ci3AU_3u|npT2md" jscontroller="KHhJQ" jsuid="ci3AU_3u">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-common-react-usage-p" jscontroller="a7qCn" jsuid="ci3AU_5b" role="heading">Common React Usage Pattern</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--9" jscontroller="a7qCn" jsuid="ci3AU_5b" role="heading">  
</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--10" jsaction="rcuQ6b:&ci3AU_5f|npT2md" jscontroller="KHhJQ" jsuid="ci3AU_5f">  
</div><div class="r1PmQe" data-hveid="CAsQAA" data-processed="true" data-wiz-uids="ci3AU_64,ci3AU_65,ci3AU_66" id="bkmrk-javascript" jscontroller="HP6Sjf" jsuid="ci3AU_63"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">javascript</div></div></div></div>```
import axios from 'axios';
import React, { useEffect, useState } from 'react';

function MyComponent() {
  const [data, setData] = useState(null);

  useEffect(() => {
    axios.get('https://api.example.com/items') // .get(url, { params: {} }) for query params
      .then(response => {
        setData(response.data); // Access data here
      })
      .catch(error => {
        console.error('Error fetching data:', error); // Detailed error handling
      });
  }, []);

  return (
    <div>
      {data ? {JSON.stringify(data, null, 2)} : <p>Loading...</p>}
    </div>
  );
}

```

# import axios from "axios";

<div data-processed="true" data-subtree="aimfl,mfl" id="bkmrk-import-axios-from-%22a" jscontroller="v48bt" jsuid="koYBDd_9" style="display: contents;">`import axios from "axios";`</div><mark class="HxTRcb" data-processed="true">is an ES6 JavaScript module statement to bring the Axios library into your project</mark>, allowing you to make HTTP requests (like GET, POST) for fetching or sending data to servers, commonly used in front-end frameworks (React, Vue) and Node.js after installing with `npm install axios` or `yarn add axios`.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="koYBDd_e,koYBDd_f,koYBDd_g"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&koYBDd_8|npT2md" jscontroller="zcfIf" jsuid="koYBDd_8">  
</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--1" jsaction="rcuQ6b:&koYBDd_k|npT2md" jscontroller="KHhJQ" jsuid="koYBDd_k">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-what-it-does" jscontroller="a7qCn" jsuid="koYBDd_l" role="heading">**What it does**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--2" jscontroller="a7qCn" jsuid="koYBDd_l" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Imports the library**: Makes all of Axios's functions (e.g., `axios.get()`, `axios.post()`) available in your file.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Enables API calls**: Lets your web app communicate with APIs to get or send data.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Uses Promises**: Handles asynchronous operations with `.then()` for success and `.catch()` for errors, or with `async/await`.</span><span class="uJ19be notranslate" data-processed="true" data-wiz-uids="koYBDd_14,koYBDd_15,koYBDd_16"><span class="vKEkVd" data-animation-atomic="" data-processed="true"> </span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--3" jsaction="rcuQ6b:&koYBDd_1a|npT2md" jscontroller="KHhJQ" jsuid="koYBDd_1a">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-how-to-use-it-%28examp" jscontroller="a7qCn" jsuid="koYBDd_1b" role="heading">**How to use it (Example)**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--4" jscontroller="a7qCn" jsuid="koYBDd_1b" role="heading">  
</div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--5" jsaction="rcuQ6b:&koYBDd_1f|npT2md" jscontroller="KHhJQ" jsuid="koYBDd_1f">  
</div><div class="r1PmQe" data-hveid="CAcQAA" data-processed="true" data-wiz-uids="koYBDd_3l,koYBDd_3m,koYBDd_3n" id="bkmrk-javascript" jscontroller="HP6Sjf" jsuid="koYBDd_3k"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">javascript</div></div></div></div>```
// 1. Install first (in your terminal): npm install axios or yarn add axios
import axios from 'axios'; // 2. Import it

async function fetchUserData() {
  try {
    const response = await axios.get('https://api.example.com/users/1'); // 3. Make a GET request
    console.log(response.data); // Log the data from the server
  } catch (error) {
    console.error('Error fetching data:', error); // Handle errors
  }
}

fetchUserData();

```

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--6" jsaction="rcuQ6b:&koYBDd_3q|npT2md" jscontroller="KHhJQ" jsuid="koYBDd_3q">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-common-scenarios" jscontroller="a7qCn" jsuid="koYBDd_3r" role="heading">**Common scenarios**</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk--7" jscontroller="a7qCn" jsuid="koYBDd_3r" role="heading">  
</div>- <span class="T286Pc" data-processed="true" data-sfc-cp="">**React/Vue**: Import at the top of your component files.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Node.js (CommonJS)**: Use `const axios = require('axios');`.</span>
- <span class="T286Pc" data-processed="true" data-sfc-cp="">**Browser (CDN)**: Include `<script src="cdn.jsdelivr.net"></script>` in your HTML</span>

# Chakra UI

<div class="Y3BBE" data-hveid="CAEQAA" data-processed="true" data-sfc-cp="" id="bkmrk-chakra-ui-is-a-popul" jsaction="rcuQ6b:&Dx6PSe_7|npT2md" jscontroller="zcfIf" jsuid="Dx6PSe_7" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 0px 0px 20px; color: rgb(10, 10, 10); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Chakra UI is a popular React component library that provides accessible, modular, and customizable building blocks to help you build frontend applications faster. Its primary advantage is excellent developer experience (DX) and style props that allow you to add CSS directly to components.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="Dx6PSe_9,Dx6PSe_a,Dx6PSe_b"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="b2b119c7-ba51-446a-81f8-52c0fdf4b472" data-processed="true" data-ved="2ahUKEwi_5PC2g7aRAxX6RioJHVbuNOAQye0OegQIARAB" data-wiz-attrbind="disabled=Dx6PSe_9/C5gNJc;class=Dx6PSe_9/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&Dx6PSe_f|npT2md" jscontroller="KHhJQ" jsuid="Dx6PSe_f" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-installation-and-set" jscontroller="a7qCn" jsuid="Dx6PSe_g" role="heading" style="color: rgb(0, 29, 53); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 20px; line-height: 28px; margin: 20px 0px 10px; font-weight: 600; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Installation and Setup<span class="txxDge notranslate" data-processed="true" data-wiz-uids="Dx6PSe_h,Dx6PSe_i,Dx6PSe_j" style="visibility: hidden;"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"><button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="5a1aed65-5df8-44ac-b8ab-68685c1e41d7" data-processed="true" data-ved="2ahUKEwi_5PC2g7aRAxX6RioJHVbuNOAQye0OegQIAhAA" data-wiz-attrbind="disabled=Dx6PSe_h/C5gNJc;class=Dx6PSe_h/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div>1. <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Create a React Project**: If you don't have one, you can use Vite or Create React App.</span><div class="r1PmQe" data-hveid="CAMQAQ" data-processed="true" data-wiz-uids="Dx6PSe_p,Dx6PSe_q,Dx6PSe_r" jscontroller="HP6Sjf" jsuid="Dx6PSe_o" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; color: rgb(0, 29, 53); margin: 16px 0px; font-weight: 400;"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); border-image: none 100% / 1 / 0 stretch; border-radius: 8px; overflow: hidden; padding: 0px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="vVRw1d" data-processed="true" style="font-weight: 500; font-size: 20px; line-height: 26px; background-color: rgb(229, 237, 255); height: 34px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1.2px solid rgb(169, 172, 170); padding: 0px 4px 0px 16px;">bash<button aria-label="Copy code text to clipboard." class="Ev0C3d" data-processed="true" data-ved="2ahUKEwi_5PC2g7aRAxX6RioJHVbuNOAQopQPegQIAxAC" style="margin: 0px; background: none; color: rgb(5, 40, 97); border: none; padding: 4px; font: inherit; outline: 0px; cursor: pointer;"><svg fill="currentColor" height="20px" jscontroller="ZfypCb" jsuid="Dx6PSe_s" viewbox="0 -960 960 960" width="20px"><path d="M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z"></path></svg></button></div><div class="pCTyYe" data-processed="true" dir="ltr" style="unicode-bidi: isolate; font-size: 14px; line-height: 22px; overflow-x: auto; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); padding: 2px 16px;"></div></div></div></div>```
    npm create vite@latest my-app -- --template react-ts
    cd my-app
    npm install
    
    ```
2. <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Install Chakra UI**: Install the core package and its required dependencies.</span><div class="r1PmQe" data-hveid="CAMQBA" data-processed="true" data-wiz-uids="Dx6PSe_y,Dx6PSe_z,Dx6PSe_10" jscontroller="HP6Sjf" jsuid="Dx6PSe_x" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; color: rgb(0, 29, 53); margin: 16px 0px; font-weight: 400;"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); border-image: none 100% / 1 / 0 stretch; border-radius: 8px; overflow: hidden; padding: 0px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="vVRw1d" data-processed="true" style="font-weight: 500; font-size: 20px; line-height: 26px; background-color: rgb(229, 237, 255); height: 34px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1.2px solid rgb(169, 172, 170); padding: 0px 4px 0px 16px;">bash<button aria-label="Copy code text to clipboard." class="Ev0C3d" data-processed="true" data-ved="2ahUKEwi_5PC2g7aRAxX6RioJHVbuNOAQopQPegQIAxAF" style="margin: 0px; background: none; color: rgb(5, 40, 97); border: none; padding: 4px; font: inherit; outline: 0px; cursor: pointer;"><svg fill="currentColor" height="20px" jscontroller="ZfypCb" jsuid="Dx6PSe_11" viewbox="0 -960 960 960" width="20px"><path d="M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z"></path></svg></button></div><div class="pCTyYe" data-processed="true" dir="ltr" style="unicode-bidi: isolate; font-size: 14px; line-height: 22px; overflow-x: auto; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); padding: 2px 16px;"></div></div></div></div>```
    npm i @chakra-ui/react @emotion/react @emotion/styled framer-motion
    
    ```
3. <span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**Set up `ChakraProvider`**: Wrap your application's root component (usually `index.tsx` or `main.tsx`) with the `ChakraProvider` to enable the theme and styling system.</span><span class="T286Pc" data-processed="true" data-sfc-cp="" style="overflow-wrap: break-word;">**`src/main.tsx` (or `index.tsx`):**</span><div class="r1PmQe" data-hveid="CAMQBw" data-processed="true" data-wiz-uids="Dx6PSe_1f,Dx6PSe_1g,Dx6PSe_1h" jscontroller="HP6Sjf" jsuid="Dx6PSe_1e" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; color: rgb(0, 29, 53); margin: 16px 0px; font-weight: 400;"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); border-image: none 100% / 1 / 0 stretch; border-radius: 8px; overflow: hidden; padding: 0px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="vVRw1d" data-processed="true" style="font-weight: 500; font-size: 20px; line-height: 26px; background-color: rgb(229, 237, 255); height: 34px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1.2px solid rgb(169, 172, 170); padding: 0px 4px 0px 16px;">tsx<button aria-label="Copy code text to clipboard." class="Ev0C3d" data-processed="true" data-ved="2ahUKEwi_5PC2g7aRAxX6RioJHVbuNOAQopQPegQIAxAI" style="margin: 0px; background: none; color: rgb(5, 40, 97); border: none; padding: 4px; font: inherit; outline: 0px; cursor: pointer;"><svg fill="currentColor" height="20px" jscontroller="ZfypCb" jsuid="Dx6PSe_1i" viewbox="0 -960 960 960" width="20px"><path d="M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z"></path></svg></button></div><div class="pCTyYe" data-processed="true" dir="ltr" style="unicode-bidi: isolate; font-size: 14px; line-height: 22px; overflow-x: auto; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); padding: 2px 16px;"></div></div></div></div>```
    import React from 'react';
    import ReactDOM from 'react-dom/client';
    import { ChakraProvider } from '@chakra-ui/react';
    import { App } from './App';
    
    ReactDOM.createRoot(document.getElementById('root')!).render(
      <React.StrictMode>
        <ChakraProvider>
          <App />
        </ChakraProvider>
      </React.StrictMode>,
    );
    
    ```
    
    <span class="uJ19be notranslate" data-processed="true" data-wiz-uids="Dx6PSe_1k,Dx6PSe_1l,Dx6PSe_1m"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="43692781-ef3b-431d-8399-3c77928d0daf" data-processed="true" data-ved="2ahUKEwi_5PC2g7aRAxX6RioJHVbuNOAQye0OegQIAxAJ" data-wiz-attrbind="disabled=Dx6PSe_1k/C5gNJc;class=Dx6PSe_1k/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--1" jsaction="rcuQ6b:&Dx6PSe_1q|npT2md" jscontroller="KHhJQ" jsuid="Dx6PSe_1q" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div aria-level="3" class="otQkpb" data-animation-nesting="" data-processed="true" data-sfc-cp="" id="bkmrk-example%3A-a-simple-lo" jscontroller="a7qCn" jsuid="Dx6PSe_1r" role="heading" style="color: rgb(0, 29, 53); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 20px; line-height: 28px; margin: 20px 0px 10px; font-weight: 600; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Example: A Simple Login Form<span class="txxDge notranslate" data-processed="true" data-wiz-uids="Dx6PSe_1s,Dx6PSe_1t,Dx6PSe_1u" style="visibility: hidden;"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"><button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="fad3c7f7-9edf-422b-bf9f-dd405347fd49" data-processed="true" data-ved="2ahUKEwi_5PC2g7aRAxX6RioJHVbuNOAQye0OegQIBBAA" data-wiz-attrbind="disabled=Dx6PSe_1s/C5gNJc;class=Dx6PSe_1s/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Y3BBE" data-hveid="CAUQAA" data-processed="true" data-sfc-cp="" id="bkmrk-you-can-use-chakra-u" jsaction="rcuQ6b:&Dx6PSe_1v|npT2md" jscontroller="zcfIf" jsuid="Dx6PSe_1v" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 10px 0px 20px; color: rgb(10, 10, 10); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">You can use Chakra UI components as building blocks, applying styles using props like `mt` (margin top), `maxW` (max width), `p` (padding), and `colorScheme`.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="Dx6PSe_20,Dx6PSe_21,Dx6PSe_22"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"> <button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="15c12ff9-3492-4ab5-b9c0-3da09c77620a" data-processed="true" data-ved="2ahUKEwi_5PC2g7aRAxX6RioJHVbuNOAQye0OegQIBRAB" data-wiz-attrbind="disabled=Dx6PSe_20/C5gNJc;class=Dx6PSe_20/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Y3BBE" data-hveid="CAYQAA" data-processed="true" data-sfc-cp="" id="bkmrk-src%2Fapp.tsx%3A" jsaction="rcuQ6b:&Dx6PSe_24|npT2md" jscontroller="zcfIf" jsuid="Dx6PSe_24" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 10px 0px 20px; color: rgb(10, 10, 10); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">**`src/App.tsx`:**<span class="txxDge notranslate" data-processed="true" data-wiz-uids="Dx6PSe_27,Dx6PSe_28,Dx6PSe_29" style="visibility: hidden;"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"><button aria-label="View related links" class="rBl3me" data-amic="true" data-icl-uuid="0dd31706-299b-4630-bae4-cd31e6474c4f" data-processed="true" data-ved="2ahUKEwi_5PC2g7aRAxX6RioJHVbuNOAQye0OegQIBhAB" data-wiz-attrbind="disabled=Dx6PSe_27/C5gNJc;class=Dx6PSe_27/UpSNec;" style="margin: 0px 6px 0px 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border: none; border-radius: 10px; height: 20px; padding: 0px; width: 28px; position: relative; outline: 0px; cursor: pointer;" tabindex="0"><span class="wiMplc ofC0Ud" data-processed="true" style="color: rgb(0, 29, 53); display: inline-block; transform: rotate(135deg);"><svg fill="currentColor" focusable="false" height="12px" style="margin-top: 3px;" viewbox="0 0 24 24" width="12px" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></button></span></span></div><div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk--2" jsaction="rcuQ6b:&Dx6PSe_2a|npT2md" jscontroller="KHhJQ" jsuid="Dx6PSe_2a" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">  
</div><div class="r1PmQe" data-hveid="CAkQAA" data-processed="true" data-wiz-uids="Dx6PSe_4o,Dx6PSe_4p,Dx6PSe_4q" id="bkmrk-tsx" jscontroller="HP6Sjf" jsuid="Dx6PSe_4n" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; color: rgb(0, 29, 53); margin: 16px 0px; font-weight: 400; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); border-image: none 100% / 1 / 0 stretch; border-radius: 8px; overflow: hidden; padding: 0px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="vVRw1d" data-processed="true" style="font-weight: 500; font-size: 20px; line-height: 26px; background-color: rgb(229, 237, 255); height: 34px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1.2px solid rgb(169, 172, 170); padding: 0px 4px 0px 16px;">tsx<button aria-label="Copy code text to clipboard." class="Ev0C3d" data-processed="true" data-ved="2ahUKEwi_5PC2g7aRAxX6RioJHVbuNOAQopQPegQICRAB" style="margin: 0px; background: none; color: rgb(5, 40, 97); border: none; padding: 4px; font: inherit; outline: 0px; cursor: pointer;"><svg fill="currentColor" height="20px" jscontroller="ZfypCb" jsuid="Dx6PSe_4r" viewbox="0 -960 960 960" width="20px"><path d="M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z"></path></svg></button></div><div class="pCTyYe" data-processed="true" dir="ltr" style="unicode-bidi: isolate; font-size: 14px; line-height: 22px; overflow-x: auto; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); padding: 2px 16px;"></div></div></div></div>```
import {
  Box,
  Button,
  Center,
  FormControl,
  FormLabel,
  Input,
  Stack,
  Heading,
  Text,
  useToast,
} from '@chakra-ui/react';
import React, { useState } from 'react';

function App() {
  const [email, setEmail] = useState('');
  const [password, setPassword] = useState('');
  const toast = useToast();

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    // In a real app, you would handle authentication here
    console.log('Login attempt with:', { email, password });
    toast({
      title: 'Login successful!',
      description: "You've successfully logged in with Chakra UI.",
      status: 'success',
      duration: 3000,
      isClosable: true,
    });
  };

  return (
    <Center h="100vh" bg="gray.50">
      <Box p={8} maxW="md" borderWidth={1} borderRadius="lg" boxShadow="lg" bg="white">
        <Stack spacing={4}>
          <Heading fontSize="2xl" textAlign="center">Sign in to your account</Heading>
          <Text fontSize="md" color="gray.600" textAlign="center">
            Enter your details below to log in.
          </Text>
          <form onSubmit={handleSubmit}>
            <Stack spacing={4}>
              <FormControl id="email" isRequired>
                <FormLabel>Email address</FormLabel>
                <Input
                  type="email"
                  value={email}
                  onChange={(e) => setEmail(e.target.value)}
                  placeholder="you@example.com"
                />
              </FormControl>
              <FormControl id="password" isRequired>
                <FormLabel>Password</FormLabel>
                <Input
                  type="password"
                  value={password}
                  onChange={(e) => setPassword(e.target.value)}
                  placeholder="********"
                />
              </FormControl>
              <Button type="submit" colorScheme="blue" size="lg" fontSize="md">
                Sign In
              </Button>
            </Stack>
          </form>
        </Stack>
      </Box>
    </Center>
  );
}

export default App;

```

<div class="Y3BBE" data-hveid="CAoQAA" data-processed="true" data-sfc-cp="" id="bkmrk-for-more-examples%2C-c" jsaction="rcuQ6b:&Dx6PSe_4t|npT2md" jscontroller="zcfIf" jsuid="Dx6PSe_4t" style="font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 16px; line-height: 24px; overflow-wrap: break-word; margin: 10px 0px 20px; color: rgb(10, 10, 10); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">For more examples, component documentation, and styling options, refer to the official <span data-processed="true" data-sfc-cp="">[Chakra UI documentation](https://chakra-ui.com/docs/get-started/installation)</span>.<span class="uJ19be notranslate" data-processed="true" data-wiz-uids="Dx6PSe_4v,Dx6PSe_4w,Dx6PSe_4x"><span class="vKEkVd" data-animation-atomic="" data-processed="true" style="white-space: nowrap; position: relative;"></span></span></div>