Denis Kulagin
Denis Kulagin

Reputation: 8937

React Native: clickable list of items

I am doing a dictionary app with lists of items like this:

Each item in the list is a link which leads to the similar list related to the word clicked.

I have two questions:

P.S. I have spotted alike functionality in the M.-W. dictionary app:

enter image description here

Upvotes: 0

Views: 2247

Answers (1)

Milore
Milore

Reputation: 1672

According to doc:

Text supports nesting, styling, and touch handling.

So I think the best solution is to properly nest your texts and pass them a function to handle the onPress action.

I will give an example code, not styled at all but completely stylable:

  onPress = (text) => {
    // do stuff
    return
  }

  render() {
    return (
      <View style={styles.container}>
        <Card>
          <Text>
          Synonyms: 
            {this.state.synonyms.map(synonym => {
              return <Text onPress={() => this.onPress(synonym)}> {synonym} </Text>
            })}
          </Text>
        </Card>
      </View>
    );
  }

And here is a snack if you wanna take a look

Upvotes: 1

Related Questions