1

I'm writing app where logic is stored in redux toolkit. Can You please tell me how can I pass data from getPostSuccess.state.post as argument of the function onGetPostHandler so I can use it in postTitle and 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 !
marcinb1986
  • 708
  • 1
  • 11
  • 30
  • 2
    What is `onGetPostHandler` supposed to be? Can you use a `useSelector` hook and select the `post` state you want to access and pass to this function? – Drew Reese Jun 25 '21 at 22:22

0 Answers0