Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

203
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda