0

I got a problem when I can't access real value of a ref created via react useRef hook.

So I have a const st = useRef(state); and inside of it there is an object with some keys and values.

I also have a useEffect hook that updates the reference for st.current.

useEffect(() => {
  st.current = value
}, [value])

So when I am doing a console.log of the st variable it shows me an object with a current key and its value is a real time reference for the object I am putting into st.current and all the values inside are correct.

But when I am trying to console.log the st.current itself it shows me the previous state of the object. And also when I am trying to access any of the variables inside the st.current it returns the previous value :(

This is the code example. Pay your attention on selectedFolders key. It shows different values for the same object. enter image description here

enter image description here

Davydoff
  • 75
  • 1
  • 7

0 Answers0