I am working on a comment section and using redux-form for taking input. I have only one Field component for taking input. But when I type in the input box all the input boxes get filled with the same value. I know this is because all these input boxes have the same name. But I only want to fill the value to the selected input box. How do I do this?
Here is my Component:
import { compose } from "redux";
import { connect } from "react-redux";
import React, { Component } from "react";
import { Field, reduxForm } from "redux-form";
import { addComment, fetchPosts } from "../../../actions/FeedPost";
import "./FeedCommentsInput.css";
import TextareaAutosize from "react-textarea-autosize";
class FeedCommentsInput extends Component {
renderField = field => {
const { touched, error } = field.meta;
const className = `comment-input-box ${
touched && error ? "red-border__error-comment" : ""
}`;
return (
<TextareaAutosize
{...field.input}
placeholder={field.placeholder}
type={field.type}
className={className}
/>
);
};
onSubmit = formProps => {
const { postid } = this.props;
this.props.addComment(formProps, postid);
};
render() {
const { handleSubmit } = this.props;
return (
<div>
<form onSubmit={handleSubmit(this.onSubmit)}>
<Field
name="text"
component={this.renderField}
type="text"
placeholder="Enter your Comment"
/>
<button type="submit">Submit</button>
</form>
</div>
);
}
}
const validate = values => {
const errors = {};
if (!values.comment) errors.comment = "Please Enter Something";
return errors;
};
export default compose(
connect(
null,
{ addComment, fetchPosts }
),
reduxForm({ validate, form: "commentbox" })
)(FeedCommentsInput);