Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!