繁体   English   中英

预期为 0 arguments,但在将 arguments 传递给 redux 工具包商店中的异步函数时得到 1

[英]Expected 0 arguments, but got 1 while passing arguments to the async func in redux toolkit store

我正在使用 Redux 工具包 + Typescript + React 创建一个项目。 我有 function 在我的 moviesSlice(作为 redux 工具包商店的一部分)中获取电影,它以 movieId 作为参数。 当我尝试在我的组件中发送这个 function 并传递这个 id 时,TypeScript 显示错误:预期为 0 arguments,但得到了 1。我该如何修复它? 谢谢

 // moviesSlice.tsx export const fetchMovie = createAsyncThunk( "people/fetchPerson", async (movieId) => { try { const response = await axios(`${BASE_URL}/films/${movieId}`); return response.data; } catch (error) { console.log(error); } } ); // store.tsx export const store = configureStore({ reducer: { people: peopleReducer, movies: moviesReducer, pl.nets: pl.netsReducer, }, }); // Movie.tsx useEffect(() => { dispatch(fetchMovie(movieId)); }, []);

这是 TypeScript。给你的 arguments 一个类型——否则创建的 thunk 动作创建者将不知道该做什么:

export const fetchMovie = createAsyncThunk(
  "people/fetchPerson",
  async (movieId: string) => {
    try {
      const response = await axios(`${BASE_URL}/films/${movieId}`);
      return response.data;
    } catch (error) {
      console.log(error);
    }
  }
);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM