React setState has nothing to do with state (5 mins)

preview_player
Показать описание
While we assume that state can be changed only by setState method and only those values which are stored in state will be updated, it is not the case.
Рекомендации по теме
Комментарии
Автор

This wouldnt work as the same in functional components where all the variables and functions declared inside component object would be re-initialized ( unless cached ) and values would get reset.

We might need to memoize values ( like using useRef, useMemo, useCallback ) in order to persist between re-renders in functional components.

In class components, on re-render, only the render method is called again and without reinitializing the properties and methods of the component object that was initialized with.

vigneshwarrv