Trying to show data in a view in React Js
, I have found an error that following the steps of the tutorial still persists:
this.state.users.map is not a function
The code is as follows
import React, {Component} from 'react';
import {render} from 'react-dom';
import request from 'superagent';
class App extends Component{
constructor(){
super();
this.state = {
users: ""
};
}
componentDidMount(){
request.get('http://localhost:8080/api/usuarios')
.end((err, res) => {
const usuariosGet = JSON.parse(res.text).usuarios;
this.setState({
users: usuariosGet
});
});
}
render(){
var mostrarUsuarios = this.state.users.map((usuario, i) => {
return (<li key={i}>{usuario}</li>);
});
return(
<div>
<h1>Hola Mundo React JS</h1>
<ul>
{mostrarUsuarios}
</ul>
</div>
)
}
}
export default App;