score:0

Accepted answer
import React from 'react'

export const getVideoComments = (newComment) => {
    return({
        type: 'GET_VIDEO_COMMENTS',
        payload: newComment
    })
};

score:1

export const getVideoComments = () => {
  return (dispatch, getState) => {
    const videoComments = getRandomComments();

    dispatch({
      type: "GET_VIDEO_COMMENTS",
      payload: videoComments
    });
  };
};

score:1

Action Creator

const getVideoComments = (comments) => ({
   type: 'GET_VIDEO_COMMENTS',
   payload: comments,
});

CommentSection.js

// handleCommentSubmit
handleCommentSubmit = (newComment) => {
   this.props.getVideoComments(newComment); //pass comment to action then access newComment in reducer then add it to your state
}

mapDispatchToProps = (state) => {
   getVideoComments: (newComment) => dispatch(getVideoComments(newComment)),
}

export default connect(mapStateToProps, mapDispatchToProps)(CommentsSection);


Reducer.js

case 'GET_VIDEO_COMMENTS':
   return [...state, action.payload];

Related Query

More Query from same tag