React and stuff

Single Page Applications (SPAs) and React

  • SPAs are important; the presentation code can be used.

  • Code is uploaded to Teams, but can also be accessed later.

  • An application interacts with a web server to edit files, communicating via HTTP.

  • When clicking a button, the page needs to be re-rendered.

Search Engine Optimization (SEO)

  • A key question is, "What is the state?"

  • Search engines need to be considered.

  • When gold duplication or maintenance updates occur, the rest bends.

  • Content is delivered when clicking on a link; details appear accordingly.

  • The hook must be properly attached.

  • User experience suffers when images take too long to load and things need redoing.

Rendering

  • Two possible actions or options exist.

  • It has to do with forms.

  • When something else happens and needs to be collapsed, it holds on to this point.

  • The Greek thing would be smoother, or a list created; if a large perfect array is ready, it updates the DOM.

  • All this happens in the background.

  • React is performant, even with complex applications.

  • React is declarative; you describe what you want, not how to do it.

Props

  • With specific fields. Use properties via Props.

  • Props are given to the component at the top.

  • When you expect properties, you pass them to the component.

useState Hook

  • Example: Component Input.

  • Multiple Components: Components can be used multiple times.

  • useState usage: const [account, setAccount] = useState(0);

  • Account is the state, and setAccount is the setter function.

  • Data types for account should be defined for later use.

  • Initial State: useState(0) initializes the state to 0.

useEffect Hook

  • Without Conditions: If useEffect is used without explicit conditions, it runs on every update.

  • Empty Dependency Array: If the dependency array is empty ([]), the effect runs only on mount (initial render).

  • Runs Twice: In development, useEffect might run twice due to versioning, but it's usually not a problem.

  • With Dependencies: If dependencies are specified, the effect runs whenever those dependencies change.

  • Example: Clicking a button increments account, triggering the useEffect with account as a dependency, causing the component to re-render.

  • event.preventDefault(): Prevents default behavior.

  • event.stopPropagation(): Stops event propagation to the next component.

Conditional Rendering

  • Renderings should only occur in specific scenarios.

  • Example: Display different content based on whether a user is logged in or not.

  • Implementation with if statements:

    • if (isLoggedIn) { return <UserGreeting />; } else { return <GuestGreeting />; }

  • Ternary Operator:

    • condition ? expressionIfTrue : expressionIfFalse;

    • Example:

      • isLoggedIn ? <UserGreeting /> : <GuestGreeting />;

  • Use Cases:

    • Loading states from a backend.

    • Checking if data (e.g., autos) has content before displaying it.

    • Hiding elements when a list is empty.

  • Checking authentication status; if not logged in, skip further checks.