Тёмный

A react interview question on counter 

Chai aur Code
Подписаться 352 тыс.
Просмотров 100 тыс.
50% 1

Visit chaicode.com for all related materials, community help, source code etc.
Sara code yaha milta h
github.com/hiteshchoudhary/
Discord pe yaha paaye jaate h:
""/discord
Instagram pe yaha paaye jaate h:
/ hiteshchoudharyofficial

Развлечения

Опубликовано:

 

25 авг 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 2 тыс.   
@tajinder715
@tajinder715 10 месяцев назад
Who is learning React for 1st time ? ❤
@endgame3842
@endgame3842 10 месяцев назад
Meee
@kizigamer6895
@kizigamer6895 10 месяцев назад
Me also but why you asked this
@RohitChhabirajYadav
@RohitChhabirajYadav 10 месяцев назад
​@@kizigamer6895😂😂😂
@user-xo8df1cn7w
@user-xo8df1cn7w 9 месяцев назад
Hitesh sir please make js and react interview questions series....
@RohitSingh-je7fb
@RohitSingh-je7fb 9 месяцев назад
16 hoga print har jagah
@tanmaypal2003
@tanmaypal2003 7 месяцев назад
I've learned this concept before from the React docs and it's called state as a snapshot. When we write setCounter(counter+1) multiple times it is updated only once because in the onclick handler of that render, even after calling setCounter(counter + 1) multiple times the value of the counter is 15, because after our event handler finishes, then React re-renders the component. They explained very well in their docs but you also explained very beautifully sir ❤❤
@heelsadhna
@heelsadhna 3 месяца назад
but if i did setcounter(++counter ) for multiple times then value increases in multiple . kindly provide me the reason
@MuhammadAbdullahMudassarMalik
@MuhammadAbdullahMudassarMalik 3 месяца назад
@@heelsadhna ++counter in React is not recommended. since you are using Set Method.
@manasXDlol
@manasXDlol Месяц назад
Detailed explaination of why does first syntax only updates the count once: Initial State: Assume count is initially 69. First Call: setCount(count + 1) schedules a state update to set count to 70 (69 + 1). Second Call: setCount(count + 1) schedules another state update to set count to 70 (69 + 1), because count is still 69 in this scope. Third Call: setCount(count + 1) schedules yet another state update to set count to 70 (69 + 1), again because count is still 69 in this scope. In case of functional updater syntax React ensures that changes are made to the latest state of the count hence each function gets access to the latest state of the count variable: First Call: setCount(count =>count+1) schedules a state update to set count to 70 Second Call : schedules a state update to set count to (70+1) because count is now 70 in this scope and so on...
@awatanshsahay7570
@awatanshsahay7570 17 дней назад
thanks bro for summarizing
@PraveenKumar-24
@PraveenKumar-24 5 месяцев назад
Namaste Guruji... Great tutorial... completed the JS Series and now learing React... Thank you for your valuable contribution to the society..
@vivekhalder2974
@vivekhalder2974 9 месяцев назад
According to me, the answer should be 19 The actual answer...... So here the function calls will be sent in batches. So, react will see them as the same operation and perform it only once. So, the counter will increase by only 1 count. To increase it by four counts, use the callback which the setCounter accepts and increase it one by one. So, the first function will be called first, the callback will be executed and the next function call will be executed.
@user-bu9fy5jg3l
@user-bu9fy5jg3l 6 месяцев назад
As a beginner in React, I am seeking every kind of knowledge regarding React. It was actually a nice video to be watched in order to get more deeper. Thanks HItesh!
@avinashrai4369
@avinashrai4369 5 месяцев назад
Can i say that it also depends on how you are passing an argument to the setterMethod; 1. If you will pass simple variable to settermethod without callbackfunction it will refer that variable which you passed as argument, because we passed 4 times the same argument which is 15 that's why we got 16. 2. On the otherhand, when we use callback() function inside setterMethod() because the settermethod() returns a updatedvar which is accepted by callback is modified one that's why we are able to increment the variable 4 times. The callback is not refering the var is we passing instead it refering the var which is in the object of useState specific variable I mean counter, setCounter are a part of single object so the setCounter is refering the counter using this.counter that's the callback gets the returned var which is updated
@saurabhbaij
@saurabhbaij 14 дней назад
I didn't understand this video in the first go.. But after reading a lot of comments and articles, now I have finally understood!
@ravipal3434
@ravipal3434 7 месяцев назад
This is really a great video on learning about the async nature of the usestate function. And i always assumed that why do we need to use the previous value while updating the state. And this was the perfect example that taught me the difference when to use the callback func in updating the state. One thing is for sure, the way you teach is awesome and starting out concepts with the problem and solution approach is really superb!!! 👍
@SatishK2022
@SatishK2022 10 месяцев назад
Value 16 hoga because setCounter ka jo last statement ha only wahi run hota ha ye or sab ko overwrite kar deta ha
@PraveenKumar-24
@PraveenKumar-24 5 месяцев назад
thanks for giving valuable indepth knowledge. this is the practical approach i learn of your video on fibre
@subashmaurya6031
@subashmaurya6031 4 месяца назад
Sir, you read in depth and explain it so that there is no need for any more videos.
@aksh1453
@aksh1453 10 месяцев назад
16 hi hoga..because react uses batch updates...which also makes states feel like asynchronous function
@theGameofwebDevelopment
@theGameofwebDevelopment 10 месяцев назад
Everyone please comment on here. The reach is important for us to motivate sir to the highest and squeeze out the best number 1 content of React in hindi from Hitech sir.
@user-ro4si4dz4e
@user-ro4si4dz4e 4 месяца назад
watching secoond time the whole series to revise the concepts , this is the best content + best teaching + best way to learn react
@thecalgarians4597
@thecalgarians4597 2 месяца назад
Sir ji, dimaag hila diya ye concept bata k. 🙏
@funnymomment769
@funnymomment769 10 месяцев назад
Sir bahut badiya ap ham logo ki kiti help kar rahe ho thank you so much sir❤❤❤❤
@nehabansal370
@nehabansal370 4 месяца назад
useState send the UI updates in batches, and as react fiber is algo behind it, while processing it will see, if you are doing the same work with same values, it will treat as one and thus here it is incrementing only once. Now, for the second scenario, where we are using prevCounter it gives the current or existing state, as it is the result of callback which will execute every time.
@sumittodankar4631
@sumittodankar4631 Месяц назад
Thanks Hitesh.! You cleared all the concepts in-depth.
@abhishekkashyap2984
@abhishekkashyap2984 10 месяцев назад
2:46 value of counter will only be incremented by 1 because react takes a snapshot of the state and render according.
@rishabhinc2936
@rishabhinc2936 7 месяцев назад
What do you mean by snapshot of the state ?
@abhishekkashyap2984
@abhishekkashyap2984 7 месяцев назад
@@rishabhinc2936 snapshot of state means , state at that particular moment
@seekhokhushise
@seekhokhushise 10 месяцев назад
Okay sir! Got it! 👍
@rahul-java-dev
@rahul-java-dev 6 месяцев назад
Interesting.....glad to know such little details !! Thank you Sir.
@PrashantGupta-vz1pf
@PrashantGupta-vz1pf 17 дней назад
so the useState( )hook has a setCounter function name can be differ but it schedules jobs in batches so all the instructions inside setCounter will be sent once altogether so it sees that all are repeated instructions so its gets executed only once. But in case of call back function syntax inside setCounter it immediately increments the value and when the next time it excutes it agian increments like that then it doesnt works in batches.
@SandeepDhama
@SandeepDhama 8 месяцев назад
16 hi hoga because counter variable mein value update nahi ho rhi hai. isliye har line 15+1=16 hi hoga.
@sumantagorai5880
@sumantagorai5880 10 месяцев назад
Great video.❤
@farhanjafri1516
@farhanjafri1516 3 месяца назад
This is the best explanation i got for callback in set method 🧡🧡
@TanyaSingh-fm1bn
@TanyaSingh-fm1bn 3 месяца назад
The setCounter is accessing the counter value which is 15 in all the multiple calls. So the answer will be 16 only as it addition 15+1 = 16 on every call. Rather if setCounter (prevValue => prevValue +1) would access the prevValue which is 15 on 1st call and prevValue = 16 on second call and so on. so for setCounter(counter + 1) // 16 always setCounter (prevCounter => prevCounter + 1) // will increase on each call. :D no cheating ;)
@sayyedaamerasharali7583
@sayyedaamerasharali7583 10 месяцев назад
First of all THANKS for such an informative series. My question is from the previous video which is related to Tailwind and props. Other than Tailwind which UI library you will prefer like there is MUI etc, Bcz some of tailwinds feature are paid. Also I am Flutter developer so CSS / Bootstrap and other designing libraries me ‘ Meri expertise nahi hai 😄 Magar Mai is se OUT nahi hona chahta hun.’ Please help me regarding this with your valuable answer .
@AbhisekMaitiOfficial
@AbhisekMaitiOfficial 7 месяцев назад
tailwindui have subscription plan but the core classes are free in tailwind
@sonuviraaj3406
@sonuviraaj3406 10 месяцев назад
Async function so it would be 16 only but if we want to log in console then it will update but not on ui....
@UEIGauravkumar
@UEIGauravkumar 6 месяцев назад
Sir aape concept ache hote hai aur ye 8 min lagta hai ki 8 second me he pura ho gya , mai to 8 din lagatar non-stop padh lu agar aese small small concepts aap dale to, just awesome concepts 😊🥰.
@vijaykumarb9622
@vijaykumarb9622 Месяц назад
Sir, I am very happy with this course and your way of teaching. Just keep your magic ON.💗
@chetansharma3310
@chetansharma3310 10 месяцев назад
Very Helpfull🔥
@chaiaurcode
@chaiaurcode 10 месяцев назад
Glad it helped
@itssaifcode
@itssaifcode 10 месяцев назад
I watched this type of question in a premium course and there it is told that react automatically takes only one of the set state, why will it take only one it was not mentioned, By watching your videos it feels like this course is better than other premium courses. Thank you so much for providing this type of content Sir.
@chaiaurcode
@chaiaurcode 10 месяцев назад
Ye channel bhi premium se kam nhi 😁
@itssaifcode
@itssaifcode 10 месяцев назад
This channel is real premium, Thank you so much again sir for helping us this much.🙏🏻
@Bhushantbn
@Bhushantbn 10 месяцев назад
@@chaiaurcode premium channel nhi ye channel to Premium Pro...... he.....sir..🙏
@ThaCoders
@ThaCoders 9 месяцев назад
@@chaiaurcode It may not happen that you also pay further after some time because collegeWallah's DSA series also did the same, taught some important things and then paid later. Sir, I feel bad to ask like this because I'll not afford paid course 😐 .
@bhagyashreenanda7049
@bhagyashreenanda7049 9 месяцев назад
100% true@@chaiaurcode
@KrishnaKumar-kh5iu
@KrishnaKumar-kh5iu Месяц назад
Managing state updates in React components React components manage state updates efficiently by re-rendering only the necessary parts. Understanding how React manages state updates through reconciliation algorithms is essential. Optimizing state updates by batching them together improves performance and reduces unnecessary renders.
@SarveshKumar-bl9in
@SarveshKumar-bl9in 4 месяца назад
thank you for this question and please bring more types of this question for interview preparation.
@bikidas5473
@bikidas5473 10 месяцев назад
4:13, there is one more aspect to this, the main thing here is the issue of react stale closure, calling set state multiple times, is setting the count to the value, where the setState function has enclosed the closure, which is the counter variable it started with, so when we pass a callback function, it is able to get the freshest value, so this is due to react stale closure issue!
@ankan-dev
@ankan-dev 10 месяцев назад
It would be 16 only as the setState is an async call
@tajinder715
@tajinder715 10 месяцев назад
hey Ankan
@ankan-dev
@ankan-dev 10 месяцев назад
@@tajinder715 hi
@tajinder715
@tajinder715 10 месяцев назад
@@ankan-dev i would like to connect with you on discord and want to take some suggestions there.
@ankan-dev
@ankan-dev 10 месяцев назад
@@tajinder715 sure my username is ankan002
@user-xj2dp8fm2q
@user-xj2dp8fm2q Месяц назад
Sir ,want more such videos !! can you please create a playlist specially for interviews in js and react.
@user-wq2jb7pl7e
@user-wq2jb7pl7e 3 месяца назад
I am feeling confident in both React and JS. Thank You Hitesh Sir 😀
@gaurav__luthra
@gaurav__luthra 10 месяцев назад
Sir could you please suggest some Javascript projects for practice ?
@chaiaurcode
@chaiaurcode 10 месяцев назад
Kaho to vo b le aaye?
@endgame3842
@endgame3842 10 месяцев назад
​@@chaiaurcodehann sir bilkul... Bcz concept to ho gya project vala confidence naa aaya hai.. Means implementation vala
@gaurav__luthra
@gaurav__luthra 10 месяцев назад
Sure sir please if you can please thanks for replying really appreciate the help.@@chaiaurcode
@sadhanarathour6683
@sadhanarathour6683 10 месяцев назад
yes@@chaiaurcode
@harshadapatil356
@harshadapatil356 6 месяцев назад
one of the best series of react!!!
@user-ix1ne2px1s
@user-ix1ne2px1s 4 месяца назад
Thank you for this helpful and amazing react series....🙏🙏
@RahulPortfolio
@RahulPortfolio 6 месяцев назад
sir it was truly interesting kindly request create more such interview question video of react it is best for our interview preparation thank you
@sunainatiwariST
@sunainatiwariST 5 месяцев назад
Bhaiyya hum log ++counter => call three times , bhi toh kar sakte the, toh jo counter variable hai uska final state hi reflect hota ..aur value yahan 3 times jump krti
@anirbanchakraborty2744
@anirbanchakraborty2744 5 месяцев назад
Just awesome teaching skills thanks a lot sir.
@krishna.vineet
@krishna.vineet 12 дней назад
3:29 I guess 16, because pehle complete hoga ye pura, then dom bnega.. and ham counter++ nhi kr rhe, counter + 1, to har baar 15+1=16 hi hoga
@arifsaleem-7377
@arifsaleem-7377 4 месяца назад
learning many new things, thanks hitesh sir
@bhargavshekhar3745
@bhargavshekhar3745 3 месяца назад
3:18 I think it should be 16 cause the value of the variable is declared outside of the scope of the function and all the SetCounter will add 15 + 1 , then after the thread will reach outside the function the value and the api will get updated but its purely a guess work based on my intuition
@003_abhishekdubey4
@003_abhishekdubey4 5 месяцев назад
Great question Sir ji
@PRINCESAHU-eb5ll
@PRINCESAHU-eb5ll 18 дней назад
Thank you for this react series
@A11-RECORD
@A11-RECORD 2 месяца назад
3:33 the set counter add one only because method over-ride in js
@debanshupati207
@debanshupati207 5 часов назад
It will not increase like this as the value of the state depend on its previous value so I think we should do something to store the previous one and with taht the new one lets see at the end its my assumption now at the last will see. edit:now after seeing we can actually take the previous state data by call back as begginer I tried to ans the question and actually I do grab the basic logic thanks sir ,i will do better from future also
@sahinpathan5197
@sahinpathan5197 10 дней назад
Intresting question ✨
@PRAKASHSAHU-jf8lx
@PRAKASHSAHU-jf8lx 2 месяца назад
really helpful sir ji ,salute❤❤
@abhisheksubhashram6910
@abhisheksubhashram6910 6 месяцев назад
Thankyou so much sir for amazing concept
@chhavimanichoubey9437
@chhavimanichoubey9437 3 месяца назад
react docs helped me a lot understanding this.
@rupeshpal7292
@rupeshpal7292 3 месяца назад
Way of explanation is damn good🙏
@PraveenSaini-yo7kq
@PraveenSaini-yo7kq 2 месяца назад
Thanks sir for explaining this interview question 😊
@adityarajboum3572
@adityarajboum3572 11 дней назад
sirji aise mind kholne wale questions aaur chahiye
@RishabhYadavJNU
@RishabhYadavJNU Месяц назад
awesome concept✨✨
@RedSpade01
@RedSpade01 6 месяцев назад
16? Yay correct answer ,didn't thought of fiber too but now I know
@ravvviii
@ravvviii 6 месяцев назад
At 03:21 i think 15 hi print hoga cz setcounter function valriable ke sath operation kar ke return kar deta hoga to baar baar call nahi hoga
@raziuddin2081
@raziuddin2081 3 месяца назад
Thanks for this concept
@Amantalks_4u
@Amantalks_4u 5 месяцев назад
Great interview lecture sir ❤
@avanishkumar1689
@avanishkumar1689 6 месяцев назад
Good content and explaination. I also watched youtube ads to pay u some rewards from youtube
@sam-zy6xq
@sam-zy6xq 2 месяца назад
great work sir ji
@saqlainkazi5770
@saqlainkazi5770 5 месяцев назад
Because of this channel I'm getting obsessed with 2 things, Chai aur Code😃
@Rohithakur07
@Rohithakur07 4 месяца назад
Thankyou so much sir for this , i am very grateful for this series ❤❤❤
@kunalgarg4922
@kunalgarg4922 Месяц назад
3:05 Increment sirf 1 se honi chahiye, kyunki function har baar same counter hi ja raha hai. Shayad...
@vlogsdiaries4250
@vlogsdiaries4250 4 месяца назад
Thank you for this great video🎉
@yogeshmalakar4196
@yogeshmalakar4196 4 месяца назад
I am learning too much for this series.
@BioChemAcademy
@BioChemAcademy 5 месяцев назад
setCounter(counter+1) multiple times it is updated only once because in the onclick handler of that render, even after calling setCounter(counter + 1) mu
@amazonsolutions1569
@amazonsolutions1569 2 месяца назад
The answer will be 16 even though we call setCounter(count +1) multiple times because when the button will clicked all count will have 15 and they increment by one so setCount will be 16.
@muzzammilnoorkhan4536
@muzzammilnoorkhan4536 Месяц назад
3:26 from when we click btn and the function call so it will not increment . Reason not store value due to number of repetition
@chiragarya4201
@chiragarya4201 5 месяцев назад
really got to know about the props
@gourabbistu9426
@gourabbistu9426 5 месяцев назад
00:03 The React interview question on counter is common and important. 01:01 Understanding state and basic operations in React. 02:09 Understanding the concept of counter in React 03:10 Understanding the concept of state in React 04:12 Using fiber and algorithm for badge updates 05:20 Updating the counter with the previous value using a hidden feature 06:28 Avoid code inconsistency by using clear variable names. 07:25 Exploring update function behavior in a React interview question
@hanzlamoghees9089
@hanzlamoghees9089 Месяц назад
Awesome🎉
@PoojaSharma-cd8qm
@PoojaSharma-cd8qm 20 дней назад
Very useful thank you sir❤
@yeshwanthvatti2200
@yeshwanthvatti2200 4 месяца назад
The Best Course in Internet.
@manasXDlol
@manasXDlol Месяц назад
I think the answer at 03:22 would be 19 , I think because Hitesh sir already explained us in Fiber architecture video, that react makes chunks of work and then render the UI rather than rendering it after every change.
@manasXDlol
@manasXDlol Месяц назад
I was wrong xd, anyways learnt something new!
@avinashrai4369
@avinashrai4369 5 месяцев назад
Okay, so behind the scene the settermethod will take a variable if we pass else because it is a part of counter variable it modifies the counter variable then it returns the updated counter which we accept in a callback function like : setCount((prevCounter) => prevCounter+1); then because we got an updated variable we can update it again. That's why earlier in simple setCount(counter+1) *4; we got only 16 means we unable to modify the counter variable because of fibre mechanism but when we used callback function now got 19😅 interesting.
@user-ny3yp5hf8t
@user-ny3yp5hf8t 5 месяцев назад
Thank you sir for this concept
@abhishekkumarmehta743
@abhishekkumarmehta743 5 месяцев назад
Awesome Content :) 🤩
@AbhayGupta-ij6ji
@AbhayGupta-ij6ji 10 дней назад
Thanks a lot...Sir🙌
@malikhaidi434
@malikhaidi434 5 месяцев назад
thank u bro for such a valuable content for free
@dhorenihal3420
@dhorenihal3420 Месяц назад
Value will remain 16 as set is a call back will go to the task queue and get executed when the call stack becomes empty
@spdwivedi5925
@spdwivedi5925 3 месяца назад
aise hi ek video bna dena sir kuch questions ki, time nikaal ke
@adityanagariya4645
@adityanagariya4645 6 дней назад
More Freshers's Interview Questions Sir
@sayanchakraborty2194
@sayanchakraborty2194 23 дня назад
Please Continue the series sir we need this
@pateldvip2106
@pateldvip2106 3 месяца назад
Great Video
@niloydas6581
@niloydas6581 2 месяца назад
Great!
@unknownHeap
@unknownHeap 3 месяца назад
Interesting one!
@vasubhatia8069
@vasubhatia8069 17 дней назад
value will be updated to 16 only and not 17,18,19 as we r not updating the variable
@aryanbasudev1
@aryanbasudev1 3 месяца назад
kya series h maja aa gaya
@enjoyyourstudyllg.k.tricks5739
@enjoyyourstudyllg.k.tricks5739 3 месяца назад
amazing biradar
@User-yb3yc
@User-yb3yc 3 месяца назад
Great sir
@ansh_mittal
@ansh_mittal 4 месяца назад
03:04 sir yeh 16 hogi. setCounter agar ek ho ya ek seh Jayda har setCounter mein counter ki initial value hi pass hogi jisse counter mein hamesha ek ka hi increment hoga.
@satvikgupta9920
@satvikgupta9920 10 дней назад
great course
@Raj_Today9613
@Raj_Today9613 5 месяцев назад
no sir this video is also good and informative thx sir for sharing lots of info
@--bountyhunter--
@--bountyhunter-- 20 дней назад
Underrated content creator
Далее
Building a react project | bgChanger
18:16
Просмотров 128 тыс.
06 Virtual DOM, Fibre and reconciliation
21:21
Просмотров 141 тыс.
The Trump rally shooting from a photographer's POV
00:58
The React Interview Questions You need to Know
21:29
Просмотров 25 тыс.
React JS Live Code Interview Round  (Mock)
18:27
Просмотров 28 тыс.
Tailwind and Props in reactjs
31:34
Просмотров 158 тыс.
useEffect, useRef and useCallback with 1 project
57:15
Просмотров 254 тыс.
Javascript Interview Questions
41:28
Просмотров 86 тыс.
Async Javascript fundamentals | chai aur #javascript
19:12
Must watch new special comedy wait for end 😆🤣
0:49
Продал не тот порошок... #shorts
1:00