[Solved] How can I POST data using API from REACTJS?


It depends on what object does onVote event from Poll component pass. But if it’s vote object, that’s required in postPoll method as second arguement, than:

  1. function in onVote event should pass poll.id from this component and vote object from Vote component onVote event itself:
                onVote={(vote) => handalchange(poll.id, vote)}
  1. handalchange should fire postPoll api method with these arguements and load updated poll data on success:
const handalchange = (pollId, vote) => {
    postPoll(pollId, vote).then(() => {
        loadPoll();
    });
}

7

solved How can I POST data using API from REACTJS?