Answer the question
In order to leave comments, you need to log in
What is the correct way to refer to the pointer to the current element of the array?
There is a code that displays a list of posts:
import React from "react";
type respX = {
"id": any,
"userId": any,
"title": any,
"body": any,
}
interface PropsI {
}
interface StateI {
data: respX[];
}
export class ComponentPostList extends React.Component<PropsI, StateI> {
state: StateI = {data: []}
async componentDidMount() {
const response = await fetch(`https://jsonplaceholder.typicode.com/posts/`);
const json = await response.json();
this.setState({data: json});
}
render() {
return (
<div className="About">
{this.state.data.map(el => (
<li key={el.id}>
{el.title}
</li>
))}
</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question