S
S
Sergey2019-12-11 17:49:16
JavaScript
Sergey, 2019-12-11 17:49:16

How to make an enter button in Redux?

Good afternoon,
Wrote at the time the comments section through React. Now, mastering Redux, I'm trying to rewrite the same code for it, I'm confused about how to implement a button for reading data from Input and Textarea.

import React from "react";

const AddComment = ({ addComment }) => {
  return (
    <form>
      <input type="text" name="name" placeholder="Введите имя" />
      <textarea type="text" name="comment" placeholder="Введите комментарий" />
      <input
        type="button"
        value="Ввод"
        onClick={ev => {
          addComment(ev.target.value);
          ev.target.value = "";
        }}
        className="submitBtn"
      />
    </form>
  );
};

export default AddComment;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Afanasy Zakharov, 2019-12-11
@afanasiyz

This task has nothing to do with Redux.
You need to store the Input and Textarea data somewhere.
You can use ref, you can use a state (or hooks)
Try to figure it out yourself, these are very basic things

B
beDenz, 2019-12-11
@beDenz

It's not clear what exactly you're confused about. Now when you click on the button, call the reducer, as a payload you will have an object with data from the form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question