S
S
Sergey2020-08-23 13:13:53
React
Sergey, 2020-08-23 13:13:53

How to get data for an individual product page?

Hello.

I install the react-router-dom module.

I am creating a product page component.
I am creating a route.

<Route path="/products/:slug" component={Product} />


Accordingly, I get the slug through the props.match.params.slug

essence of the issue:
Inside the page component, fetch data on the slug that I get from the props. I receive this data in state. I get the stey itself through useSelector. And when I try to display the data, they do not have time to load, because useSelector works faster than the data is loaded from the back. Tell me how to solve?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alex4answ, 2020-08-23
@justedoit

Add a loading flag to the state, for example, set isFetching: true at the beginning, and add a loading indicator
at the end of loading isFetching: false and display the loaded data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question