Exercises: useState Hook - React In Depth

Поділитися
Вставка
  • Опубліковано 21 жов 2024

КОМЕНТАРІ • 16

  • @brians4265
    @brians4265 9 місяців тому +1

    Hi Nader ,here is my solution to the bonus exercise , I haven't looked at your solution yet. import { useState } from "react";
    export const Counter2 = () => {
    const [count, setCount] = useState(0);
    function handleClick() {
    setCount((prev) => prev + 1);
    setCount((prev) => prev + 1);
    }
    return (
    {count}
    +
    );
    };
    by the way, it's amazing what you do for us and you are an amazing teacher. Thank you for what you do😊

  • @CaliburPANDAs
    @CaliburPANDAs Рік тому +5

    Nader best teacher 🚀

  • @MrGoofy-hu5st
    @MrGoofy-hu5st 6 місяців тому

    Thanks for the content Nader. I like how you go into the depth of each topic you teach and provide exercises for it, which is very hard to find. Awesome content!

  • @MyPukeko
    @MyPukeko 9 місяців тому +1

    Thank you very much Nader for your teachings. My answer for exercise 3 (not prop-drilling the state to the button) is:
    function Button({ setString }) {
    function handleClick() {
    setString((str) => (str === 'Logged In' ? 'Logged Out' : 'Logged In'));
    }
    return (

    Toggle Login

    );
    }
    export default Button;

  • @edithsylvester1311
    @edithsylvester1311 Рік тому +1

    You have the best videos Nader

  • @HumairaFatima-wf9me
    @HumairaFatima-wf9me 10 місяців тому +1

    Great 👍 working

  • @joeyreyes9666
    @joeyreyes9666 7 місяців тому

    for exercise 3 i set my state to const [login, setLogin] = useState(true) and then made my handle click :
    const handleClick = () => {
    setLogin(!login);
    console.log(login);
    };
    and then my p tag to:
    {login ? "Logged in" : "Logged Out"}
    Worked like a charm

  • @shadmanzaman435
    @shadmanzaman435 8 місяців тому

    Hey Nader! so in 1:02:50, as setCount is asynchronous, both are sent to the callback queue, the first setCount returns its value and the count variable is replaced with its assigned value 0 so -> 0 + 1, the second setCount also returns -> 0 + 1 so both their state changes are compared and since the second setCount has no change in state (compared to first) , second one has no effect, is this why the count was being updated by one?

  • @logicweaver7152
    @logicweaver7152 4 місяці тому

    Need clarification on when exactly rerendering is triggered? Is it immediately triggered on encountering setState function? From what I see, it doesn't seem to be the case?

  • @HammadAli-f1y9j
    @HammadAli-f1y9j 7 місяців тому

    how can we save in state the values from inputs in "Forms exercise" timestamp:43.37.

  • @saltech2024
    @saltech2024 Рік тому +1

    Hi great