Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
Wrapping textarea as a React component and exposing value

I have wrapped a <textarea /> tag as a react component which sits inside of an Ant Design Form.Item like so:

<Form.Item
  name="query"
  label="Query"
>
  <CodeEditor />
</Form.Item>

the issue is that when I submit the form, the value for "query" is undefined.

If I replace <CodeEditor /> with the text area code like so:

<Form.Item
  name="query"
  label="Query"
>
  <textarea />
</Form.Item>

the "query" value is set correctly.

How should one wrap form tags in React so that their native props/functions are exposed? I would expect refs to work here but I assume there is a better approach.

EDIT

CodeSandbox example. If you enter some text into the CodeEditor input and click the "Console Log Query" button, "undefined" will be logged. But if you replace on line 22 with <textarea /> the query value will be logged.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Instead os using:

 <Form.Item
   name="query"
   label="Query"
 >
    <textarea />
 </Form.Item>

You can try this component imported from antd as shown below:

import { Input } from 'antd';

const { TextArea } = Input;

<Form.Item
  name="query"
  label="Query"
>
  <TextArea />
</Form.Item>
about 4 years ago · Juan Pablo Isaza Denunciar

0

If you want to use custom component as a children of Form.Item you should provide value and onChange props to it, because Form.Item will use them for changing the Form Instance.

In your case the code of CodeEditor component will look like this:

function CodeEditor({ value, options, readOnly, onChange }) {
  const textRef = React.useRef();

  return (
    <Editor
      value={value}
      ref={textRef}
      language="sql"
      placeholder="Please enter SQL code."
      onChange={onChange}
      padding={15}
      style={{
        backgroundColor: "#f5f5f5",
        fontFamily:
          "ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace",
        fontSize: 16
      }}
    />
  );
}

Link to codesandbox

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda