Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
How to get data of specific selected item

I am using external API of getting my data, that I fetch with axios.

I am able to receive data and map through them without any issues, but I need to be able to click on specific item from data and go to another page, that shows detailed data of that specific click item

(you can imagine it as blog that has blog posts and when you click on individual post, you get data only related to that post)

This is how I fetch my items in parent component:

 const [items, setItems] = useState([]);

    useEffect(() => {
        const getItems = async () => {
            try {
                const response = await axios.get(
                    'APIendpoint'
                );
                console.log(response);
                const final = response.data;
                setItems(final);
            } catch (error) {
                console.log(error);
            }
        };
        getItems();
    }, []);

And just mapping through them, with Link to another page:

 {items && items.map((item) => (
                        <div key={item.id}>
                            <Link to={`/closet/${item.id}`}>{item.name}</Link>
                        </div>
 ))}

And my router, which works and url does update:

<Route exact path="/"><App /></Route>
<Route exact path="/:id"><Component items={items}/></Route>

Now in Component.jsx I tried to do something like this:

const Main = ({ items }) => {

 useEffect(() => {
        const getDetail = async () => {
            try {
                const response = await axios.get(
                    `APIendpoint/${closetItems.id}` // path to the id 
                );
                console.log(response);
                const detail = response.data;
                setClosetItems(detail);
            } catch (error) {
                console.log(error);
            }
        };
        getDetail();
    }, []);

But nothing is happening when I console.log(closetItems) - I am not familiar with it, am I on right path or do I have to change the strategy?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!