Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Attempting to capture value of dynamically created buttons
Post Flair (click to view more posts with a particular flair)
Post Body

I've set out to create my first solo react app and running into some issues with dynamic content. Below, I dynamically output buttons off a map method from local JSON data (simulating a DB call for down the road). The buttons generate the way I want, but I want to pass their key/id to another component that will output the rest of the data (like a user profile page). I am stuck on how to get the value from the button to the next component <Animal /> that is hidden with a modal state. The idea is to pass the key/id and for the component to populate data from that specific JSON index.

import React, { useState, Fragment } from 'react';
import adata from '../data/AData.json'
import Animal from './Animal'

const AnimalList = () => {
    const [show, hide] = useState (false);   

    return(   

        <div>
            {
            adata.adata.map(
                adata => <div key={adata.id} id={adata.id}>
                            <button onClick={() => hide(true)}>{adata.name}</button>
                        </div>) 
            }
            <Fragment>
                <div>
                    {show ? <Animal />: null}
                </div>
            </Fragment>
        </div>
        ) 
}

export default AnimalList;

Author
Account Strength
90%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
3,032
Link Karma
283
Comment Karma
2,743
Profile updated: 3 days ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago