Reactjs Interview Questions | useEffect |

preview_player
Показать описание
Reactjs Interview Question | useEffect related question
Рекомендации по теме
Комментарии
Автор

Wow Look how easy to read and understandable this react Code is. Such innovative.

MAGIHAG
Автор

Testing against examples that don’t make logical sense is so silly.

moodrow
Автор

Its still gonna cause an endless loop.
The useEffect is unnecessary. If you update a value inside a useEffect that depends on the value, you are just shooting yourself in the foot. And the logic too doesn't make sense anyways.
Remove the useEffect completely, it just introduces more errors. ESLint is good for catching TypeErrors and maintaining clean code, but you shouldn't use it to detect bad logic. (This is a simple snippet so it might be overkill to use TDD but you should use TDD for testing the logic of an app that is more complex)

Also, why is useEffect imported on a seperate line but useState isn't? 👀

Dev-Siri
Автор

I wish react interviews were this easy xD

Sweet_Solos
Автор

If the react strict mode is on then the useEffect will run 2 or 3 times else it will run only 1 time that mean the value of count will be 0 for ever in that code

shayanalijalbani
Автор

🤣 😂 no increase or decrease or timer function, no need useEffect, unless timer function is used, display on <div > what else !?? It’s kinda good question for junior level,

EricEGunes
Автор

Correct, in what context? One can spin up a few functions from this.

adevikthur
Автор

1 array dependency isn't there
2 setCount(count+1)

ujjwalsrivastava
Автор

I am sorry but it kinda made me iritated when he/she provided the solution (cause it is an horrible solution and it dosent make any logical sense)

phalakjatin
Автор

useEffect not have dependency so the program will run Infinite loop and state value always gives us 0 because of state value not be increment

rsdeathgaming
Автор

There is no dependency bracket in useEffect

dharineeshgg
Автор

Christ, it is still so wrong. Who gave you that idea that you can update value inside the useeffect when this useeffect depends on this value. This will lead to the endless rerender cycle

tolikcooks
Автор

First question is wtf do you even want this code to do.

Then delete whatever this is and start over

alext
Автор

The value of count never changes??? Its always zero.

chippandenga
Автор

since the value of count will remain the same it won't rerender the component.

sandeshsawant
Автор

dependency is missing [ ]
add this in useeffect end

WaqarAhmad-qzmv
Автор

Interesting.

With strict mode off, this would do a react render pass once, right? But if you had a button that sets count, to say count+1, you'd see a double react render pass, on each click.

If you had a useReducer, which just sets state to the dispatched action, you'd see an initial double render.

elgalas
Автор

2nd argument not available which is array [ ]

rajumaurya
Автор

If the goal of this code is to make the component rerender infinitely, then its not correct.

I believe the setCount woundn't cause a rerender because the value of 'count' does not change.

lawliet.fortyfour
Автор

Clarifying questions first.

1. what is the expected behavior.

If it is to just display the count then just use count as a prop. Getting rid of all the hooks which are useless.

If there is supposed to be a button that increments count, then the buttons onClick handler should call setCount((prev) => prev++) since there is a closure on count.

CodeDreamer
welcome to shbcf.ru