Component not showing data after useRef
Hello,
A little explanation before the code:
I am fetching data from a database asynchronously. Fetches just fine using the function
fetchData
. Then to stop continuous re-rendering I use useRef instead of useState to set two arrays cdata
and pdata
. Their console.log
shows it worked.
However, when I call my component after onclick
neither cdata
nor pdata
are available.
I cant use useEffect
as I need my data to be available after onclick
and fetchData
within useEffect
means it is only available after the page re-renders. Not at onclick
.3 Replies
Now the code:
I only get 'No counts yet' despite the fact that
console.log
does show cdata
and pdata
correctly.
If anyone could help me out I would be greatly obliged.Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Thank you for your answer. I have understood what you are saying. Let me try going back to useState and useEffect with what you have mentioned.