P
P
Portal_Shooter2021-10-01 12:06:37
React Native
Portal_Shooter, 2021-10-01 12:06:37

How to use hooks in a loop?

There is a list of blocks. It is necessary to make it so that when you click, the style of this block changes. I don't know how to implement it. I know that this cannot be done in a loop due to the possibility of breaking the order of the hooks, but how can this be done?

<FlatList
  data={arr}
  numColumns={7}
  renderItem={item => {
    item.state = 'noActive';
    console.log(item);
    return (
      <TouchableWithoutFeedback
        onPress={() => (item.state = 'active')}
        style={styles.fullContainer}>
        <View style={[styles.block, styles[item.state]]}>
          <Text>{item.item.name}</Text>
        </View>
      </TouchableWithoutFeedback>
    );
  }}
/>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Berezansky, 2021-10-03
@Portal_Shooter

but how can this be done?

You can create a separate component for TouchableWithoutFeedback and store states and styles in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question