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😊
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!
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 (
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
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?
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?
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😊
Nader best teacher 🚀
For sure!
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!
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;
You have the best videos Nader
Thanks Edith! 😊
Great 👍 working
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
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?
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?
how can we save in state the values from inputs in "Forms exercise" timestamp:43.37.
Hi great