いくつかのムービーを返すJsonファイルに対してAjaxリクエストを作成しています。Reactネイティブ状態が変更されていません
state = { movies: [] };
componentWillMount()
{
this.getMovies();
}
/*
Make an ajax call and put the results in the movies array
*/
getMovies()
{
axios.get('https://pastebin.com/raw/FF6Vec6B')
.then(response => this.setState({ movies: response.data }));
}
/*
Render every movie as a button
*/
renderMovies()
{
const { navigate } = this.props.navigation;
return this.state.movies.map(movie =>
<ListItem key={ movie.title }
title={ movie.title }
icon={{ name: 'home' }}
onPress={() =>
navigate('Details', { title: movie.title, release: movie.releaseYear })
}
/>
);
}
render() {
return(
<List>
{ this.renderMovies() }
</List>
);
}
私が手にエラーは次のとおりです:this.state.mapは関数ではありません。これは映画がまだ空だからです。
私がconsole.log response.dataを実行すると、JSONファイルからすべての行が返されます。問題はこの行の可能性が最も高いです:
.then(response => this.setState({ movies: response.data }));
誰かが間違っていることを知っていますか?
チェックこのhttps://stackoverflow.com/questions/47027035/why-is-my-react-component-this-state-updateclothing-saying-undefined-even-thou/47028520#47028520 –
結合問題で'getMovies'関数 –
@Raidersあなたのjsonレスポンスの形式が間違っています。チェックアウトしてください。 – jason