I am trying basic react js api data display on to the DOM.
I am getting this error:
On the console I dont get any errors but it gives TypeError: Cannot read property 'map' of undefine error on the page.
class App extends React.Component {
constructor(props)
{
super(props);
this.state = {
details: [],
isLoaded: false
}
}
componentDidMount()
{
fetch("https://dummy.restapiexample.com/api/v1/employees")
.then(res => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
details: result.details
})
}
)
}
render() {
const { isLoaded, details} = this.state;
if(!isLoaded)
{
return <div> Loading ...... </div>
}
return (
<ul>
{details.map(detail => (
<li key={detail.employee_name}> {detail.employee_name} </li>
))}
</ul>
);
}
}
export default App;
details && details.mapassuming details is really an array