MerajM
Reactiflux3y ago
4 replies
Meraj

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
.
Was this page helpful?