import React, { Component } from "react"
export default class Main extends Component {
constructor(props) {
super(props)
this.state = {
role: ["a","b","c"],
display: "",
}
}
componentDidMount() {
for (let i of this.state.role) {
setTimeout(() => {
this.setState(() => { display: i})
}, 2000)
}
})
}
render() {
return (
<>
<h3>{this.state.display}</h3>
</>
)
}
}
It is only printing the last element in the array