0

I want to handle each string of my item.fieldtype result, but i'm not finding a way to do it someone knows how?

....
      <SafeAreaView style={{flex: 1}}>
          <View>
            {Object.keys(Body).length > 0 ? (
              Body.map(item => <Text key={uuid.v4()}>{item.field}</Text>
              // if (item.fieldtype == "Numeric") <Text>Numeric</text> ===> apply here
              //else if (item.fieldtype == "Text" ) <Text>Text</text> ===> "" ""      
              )
            ) : (
              <Text>Testado</Text>
            )}
          </View>
        </SafeAreaView>
...

1 Answer 1

1

You can use a fragment tag (or just a View) and return multiple items in the map:

<SafeAreaView style={{flex: 1}}>
  <View>
    {Object.keys(Body).length > 0 ? 
      (Body.map(item => 
       <React.Fragment key={uuid.v4()}>
          <Text>{item.field}</Text>
          {item.fieldtype == "Numeric" ? <Text>Numeric</Text> : null}
          {item.fieldtype == "Text" ? <Text>Text</Text> : null}
       </React.Fragment>))
      : (<Text>Testado</Text>)}
  </View>
</SafeAreaView>

(Note that it would be ideal if you had useable stable ids rather than generating a new uuid for each item on each render)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.