R
R
Roman2019-11-24 23:40:01
React
Roman, 2019-11-24 23:40:01

How to get data from api on click and immediately after that direct to another route?

Hello, I have a component (route) that in componentDidMount loads a list of categories from the api, and when I click on any category, I first get the elements of this category and transfer me to another route. And I can do ONLY ONE THING: either use the Link component to go to the route I need BUT then I CANNOT GET DATA WHEN CLICKING, or not use Link and instead of it, like a button tag, when I click on which I can call a method that I need will receive the data and upload it to that route, but then I won’t be able to go there, just change the link to that route on the command line (then everything works naturally). I tried to do when clicking on the button > call the method that receives the data > redirect did not work. How do they solve this problem in the modern world? I hope the essence of the question is clear.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Didenko, 2019-11-25
@Isildur12

Why do you need to do this on click? Throw your call method in componentDidMount and everything will work when you switch to the route you need. What's the point of getting the list first?
If you really need it, although xs why, then make a regular element, when you click on it, hang up a request and in .then check if the data has arrived, if it has, then do history.push()

I
IDONTSUDO, 2019-11-25
@IDONTSUDO

https://github.com/IDONTSUDO/Snake-Cup/blob/master...
Smoke

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question