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

204
Vistas
React Native Arrow Function - using arguments as a state name

I have a client request to add a long sign off form to their RN app. The form has several yes no answers - if yes is selected the user is presented with a text box to provide further details.

I wanted to create a simple return function to create the relevant return the relevant code for each question.

This is what i have so far:

returnCommentsBox = (parentSelector, labelText, thisState) => {
  

  return (
    <View Style={{parentSelector} && EL_Styles.dontShow}>
      <Text style={FormStyles.formLabel}>
        {labelText}
        <Text style={FormStyles.redHigh}>*</Text>
      </Text>
      <View style={FormStyles.textInputBlock}>
        <TextInput
          placeholder="Please Enter Details"
          style={FormStyles.textInputText}
          value={**{thisState}**}
          autoCorrect={false}
          numberOfLines={4}
          multiline
          style={{
            minHeight: 280,
            height: 'auto',
            textAlignVertical: 'top',
          }}
          returnKeyType="done"
          onChangeText={(text) => this.setState({**thisState**: text})}
        />
      </View>
    </View>
  );
};

The bold parentSelector and thisState arguments here are state names, the labelText is a simple text title.

they are called as follows:

{this.returnCommentsBox(
       'gutterInspection',
       '2b. Please enter further details',
       'gutterComments',
  )}

In the above example - the returned object provides the text as it should - but the state names aren't working as expected at all. as in the states aren't updated and the conditional style isn't working. Is this because the argument is supplied as a string? Or the syntax used to embed the argument into the code? Can anyone please help me understand how to make this work?

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

0

I think you are giving the property keys to the returnCommentsBox function. You can select the value of this property from the EL_Styles and this.state objects by property like this:

returnCommentsBox = (parentSelector, labelText, thisState) => {
  return (
    <View style={[EL_Styles[parentSelector], EL_Styles.dontShow]}>
      <Text style={FormStyles.formLabel}>
        {labelText}
        <Text style={FormStyles.redHigh}>*</Text>
      </Text>
      <View style={FormStyles.textInputBlock}>
        <TextInput
          placeholder="Please Enter Details"
          style={FormStyles.textInputText}
          value={this.state[thisState]}
          autoCorrect={false}
          numberOfLines={4}
          multiline
          style={{
            minHeight: 280,
            height: 'auto',
            textAlignVertical: 'top',
          }}
          returnKeyType="done"
          onChangeText={(text) => this.setState({ [thisState]: text })}
        />
      </View>
    </View>
  );
};
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