Search code examples
javascriptreactjsreact-final-formfinal-form

how to getvalue of textarea in react?


I am using react-final-form and TextareaAutosizein my example .I am trying to get the value of text-area but not able to do that. I am able to get value of input field but not textarea

here is my code https://codesandbox.io/s/react-final-form-simple-example-rd3rc

 <div>
            <label>Text area Name</label>
            <Field
              component={TextareaAutosize}
              type="textarea"
              name="operatingPinCode"
              placeholder="Notes"
              label="About"
            />
          </div>

API link https://final-form.org/docs/react-final-form/examples/simple

https://www.npmjs.com/package/react-textarea-autosize


Solution

  • Your final-form code is working fine. The problem I think lies with TextAreaAutosize, since it doesn't know how to pass data directly to your form. So you might need to add a handler on that field for the onChange event.

    Based on the final form documentation, this code sample below seems to work just fine:sandbox-code Just checkout the second attempt section.