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

151
Vistas
How to make a wrapper interchangable?

I am facing a problem with my formik fields and need to use FastFields in some situations and Fields in others. Therefor my FormikControl, a class for building formik inputs needs to switch between and as wrappers. I am not sure how to do this. Here is part of the class:

const FormikControl = (props) => {
  const {
    name,
    type,
    label,
    disabled,
    fullWidth,
    isDynamic, // Field (true) or FastField
  } = props;
  const classes = useStyles();

  const inputProps = {};

  switch (type) {
    case 'text':
      return (
        <>
          <ComplexField name={name} isDynamic={isDynamic} {...props}> // meant to be the wrapper that switches
            {({ field }) => {
              return (
                <TextField
                  {...field}
                  variant="standard"
                  label={label}
                  fullWidth={fullWidth}
                  disabled={disabled}
                  InputLabelProps={{
                    shrink: true,
                  }}
                  InputProps={inputProps}
                  value={field.value || ''}
                />
              );
            }}
          </ComplexField>
          <ErrorMessage error name={name} component={FormHelperText} />
        </>
      ); 

ComplexField is meant to be the flexable wrapper and needs be able to switch between Field and FastField based on "isDynamic". My best try was this:

const ComplexField = ({ name, children, isDynamic, ...props }) => {
  return isDynamic ? (
    <Field name={name} props={props}>{({ field }) => children({ ...props, field })}</Field>
  ) : (
    <FastField name={name} props={props}>{({ field }) => children({ ...props, field })}</FastField>
  );
};

Didn't work :(

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

0

<ComplexField name={name}>

You're not passing there the prop "isDynamic" Is it intentional? Because like that it's obvious that doesnt work

<ComplexField name={name} isDynamic={isDynamic}>

If you want to use a better pattern, read that Conditionally render react components

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