1
I have the following code:
const Sounds: React.FC = () => {
const [hasSelect, setHasSelect] = useState(false);
return (
<Container>
<FlatList
data={data}
keyExtractor={item => item.id}
renderItem={({ item }) => (
<Sound key={item.id} activeOpacity={0.7}>
<MusicPic source={mushroom} />
<AddSound onPress={() => setHasSelect(true)}>
<ICon name="library-plus" color={hasSelect ? main : lighter} />
</AddSound>
</Sound>
)}
/>
</Container>
I’m trying to change the icon color when the user clicks on it, but all Flatlist icons have the status changed, as I do to change only the pressed?
You want to select one at a time or can more than one be selected at the same time?
– mico
Who would need to control that state is the
<Sound>
, nay<Sounds>
... Or else it would control<Sounds>
but through a Boolean/object array, not a single Boolean– Rafael Tavares
Thanks Rafael, I created a separate component for each Sound and I passed the props for this component there and everything worked out, thank you very much
– Nycollas