所以我想做的基本上是调用async函数,而不是要求mapStateIntoProps将其传递给props到实际组件中。当我这样做时,会看到显示未决数据的console.log()。
here is my first file that has the async func
export const getIdMovie = async (state,movieId)=>{
let data= await axios
.get(
`https://api.themoviedb.org/3/movie/${movieId}?
api_key=${APIKEY}&language=en-US`
)
let results=data.data
return results
}
this is where i try to call it on the second file
injectDataReducer(store, { key: "movie", reducer: MovieReducer });
const mapStateToProps = (state, ownProps) => ({
movie: getIdMovie(state,ownProps.movieId)
});
答案 0 :(得分:0)
如果getIdMovie是操作创建者,则必须使用redux-thunk。Reducer在分派和操作时异步更新存储,以避免通过多个分派操作更改相同的数据。
````此外,您还必须首先将状态设置,即电影设置为reducer,然后从那里将数据更新到您的组件中。''``