I am new using react and I'd like to get data from server, so I tried:
class App extends React.Component {
constructor(props) {
super(props)
this.state = { movies: [] }
}
componentDidMount() {
axios.get('https://facebook.github.io/react-native/movies.json')
.then(response => this.setState({ movies: response.data.data }))
}
renderUsers() {
const { movies } = this.state
return movies.map( user => (
<div key={id}>{title} {releaseYear}</div>
))
}
render() {
return <div>{ this.renderUsers() }</div>
}
}
ReactDOM.render(
<App />,
document.getElementById('container')
)
and my html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title></title>
</head>
<body>
<div id="container"></div>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/axios/dist/axios.min.js" crossorigin></script>
<!-- Load our React component. -->
<script src="movies.js" type = "text/babel"></script>
</body>
</html>
the problem is, I get nothing in my page. any ideas what is wrong?
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>in your head section. If that's not it, then use the developer console of your browser and share any error messages you see.response.data.moviesinstead ofresponse.data.data. Another problem I see is, inrenderUsersit should be<div key={user.id}>{user.title} {user.releaseYear}</div>. You might wanna usemovieinstead ofusertoo.