79570698

Date: 2025-04-12 16:36:08
Score: 0.5
Natty:
Report link

this is a very classical issue for a beginner/junior react dev. See in the first case, when you are using your own custom hook to fetch data, it is not triggering any re-renders in your component, so even though you fetched the data, it is not rendered in your UI. Your function getData() in first case changes the state in setData() but you need to trigger a DOM event to render the data in front. Try using this getData() function with a useEffect hook and you will see the difference on your own. Take a look in docs or online on how the DOM and DOM event works in react.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Single line (0.5):
  • Low reputation (1):
Posted by: PythonOp