TL;DR —
React's useRef hook is a perfect way to share the state between each render without causing a new render. It is not good practice to keep anything outside the component. Every render create its own scope and each scope has its own state. UseRef returns a mutable ref object whose current property is set to be updated each time the component re-rendering is re-rendered. The state is set after the component was rendered and set a new state after each render is rendered. It works, but it is not a good idea to keep state outside of component.
[story continues]
Written by
@kliukovkin
Software Engineer
Topics and
tags
tags
reactjs|react-hooks|react-hook|javascript|software-development|frontend-development|website-development|react
This story on HackerNoon has a decentralized backup on Sia.
Transaction ID: eW94Od75cLqcI4JAR5TDvJJSeRtmngyh_FdhxtKWQ2I
