如何将 redux 工具包状态作为要用于另一个函数的函数参数传递

时间:2021-06-25 20:55:14

标签: reactjs redux redux-toolkit

我正在编写应用程序,其中逻辑存储在 redux 工具包中。你能告诉我如何将来自 getPostSuccess.state.post 的数据作为 onGetPostHandler 函数的参数传递,以便我可以在 postTitle 和 postBody 中使用它

    export const postSlice = createSlice({
  name: "post",
  initialState: initialPostState,
  reducers: {
    getPost: (state) => {
      state.loading = true;
    },
    getPostSuccess: (state, { payload }) => {
      state.post = payload;
      state.loading = false;
      state.hasErrors = false;
    },
    getPostFailure: (state) => {
      state.loading = false;
      state.hasErrors = true;
    },
  },
});



  export const onGetPostHandler = () => {
      let i = 0;
      const postTitle = post[i].title;
      const postBody = post[i].body;
      i++;
    };

thanks !

0 个答案:

没有答案