I get an API response and I can display all 20 results from the response and all 20 descriptions. I want to display them by index and they are already indexed in the response. I don't know how to select the object in the array of articles and display a specific article.
Here is my response:
And here is my code:
render() {
let articles = this.state.articles;
return (
<div>
<ExpansionPanel>
{articles.map(article => (<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}><Typography>{article.title[0]}</Typography></ExpansionPanelSummary>))}
<ExpansionPanelDetails>
{articles.map((article) => (
<Typography>{article.description}</Typography>
))}<br />
</ExpansionPanelDetails>
</ExpansionPanel>
</div>
);
//Fixed article title but article description is repeating.
I can specify what title I want to get however when I use this.state.articles[0].description I get repeating results in the drop-down.
Correlating code:
<ExpansionPanel>
{articles.map(articles => (<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}><Typography>{this.state.articles[1].title}</Typography></ExpansionPanelSummary>))}
{articles.map((articles) => (<ExpansionPanelDetails><Typography>{this.state.articles[1].description}</Typography></ExpansionPanelDetails>))}<br />
</ExpansionPanel>
// Added new snippet
{articles.map((articles, index) => (
<div>
<ExpansionPanel key={index}>
<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}><Typography>{this.state.articles.title}</Typography></ExpansionPanelSummary>
<ExpansionPanelDetails><Typography>{this.state.articles.description}</Typography></ExpansionPanelDetails><br />
</ExpansionPanel>
</div>
))}
// Fixed... had to use the property articles instead of this.state.articles. This fixed the repeat issue and the display issue.

