I'm new in react and I've some doubts about how to iterate over a json response without using jsx cause I'm only able to use react adding it with scripts tag in the html file. Also Babel it's not an option.
I found this https://babeljs.io to convert jsx to createElement but it didn't work eather
This is my json response:
{
"user": {
"userId": 1,
"fullName": "xxxxx",
"ldapId": "xxxx",
"contraseña": "xxxxxx!",
"email": "c@mail",
"deleteFlag": "N ",
"access": "Y ",
"roles": [
{
"roleId": 2,
"roleName": "Admin",
"focusAccount": "N ",
"channelAccount": "N ",
"menuHome": null
},
{
"roleId": 1,
"roleName": "Dashboard",
"focusAccount": "N ",
"channelAccount": "N ",
"menuHome": null
}
]
}
}
Reactjs code:
class User extends React.Component {
state = {
user: []
}
componentDidMount() {
axios.get('http://localhost:8080/dashboard?user=' + localStorage.getItem("user"))
.then(res => {
const user = res.data;
this.setState({ user });
})
}
React.createElement("ul", null, (void 0).state.user.map(function (user) {
return React.createElement("li", null, user.fullName);
}))
}
ReactDOM.render(User, document.getElementById('root'));
In this case I suppose even if I'm doing a map over user, and I know that user it's just one, It should create one li tag inside the ul tag.
Thanks in advance.
useris an object. If you want to operate as an array you can use. Array.from or[ state.user ].map