I receive data from an open api which is stored in an array in state. Then I mapped the array to output it in list items and gave them keys additionally. (this is working so far)
- I want to display the position of every element in the array in another list items. (this is not working). (The result should be 1-17 of course).
- Then I want to compare every elements position to a given position. So, if ItemPosition[5] = 6 do...
import React, { Component } from 'react';
import axios from 'axios';
import './App.css';
class App extends Component {
state = {
teams: []
}
componentDidMount() {
axios.get(`https://www.openligadb.de/api/getbltable/bl1/2019`)
.then(res => {
const teams = res.data;
this.setState({ teams });
})
}
render() {
return(
<ul>
{this.state.teams.map(p => <li key={p.id}>{p.TeamName}</li>)}
// next line is not correct
{this.state.teams.map(t => <li key={t.id}>{t.key}</li>)}
</ul>
);
}
}
export default App;