I’m building an online store with React. The product details page won’t show up even though there are no errors in the console. I’ve tried using useParams but it’s giving me an undefined params error. Here’s a simplified version of my code:
yo iris85, hav u checked the network tab? sometimes the api fails silently. check if ur reducer updating state correctly after fetch. if not, add some console.logs in useEffect to verify its firing. react can be a bit tricky sometimes, so good luck debugging!
Have you verified that your Redux store is properly set up and connected to your component? It’s possible the issue lies there. You might want to use the Redux DevTools browser extension to inspect your store state and action dispatches in real-time. This can help pinpoint where the data flow breaks down.
Another thing to check is your API endpoint. Are you certain it’s returning the expected data? You could try making a direct API call using a tool like Postman to confirm the response structure.
Lastly, consider wrapping your component render in a conditional check:
Hmm, that’s a tricky one! Have you checked if the fetchItemInfo action is actually being dispatched? Maybe try adding a console.log right before the dispatch to make sure it’s hitting that point.
Also, I’m curious about your routing setup. Are you using React Router? If so, which version? In newer versions, you might need to use useParams hook instead of accessing match.params.