Реагировать на собственный флажок

Я хочу создать собственный флажок в реагировать на родной, и я почти там, но единственная проблема, которую я не смог решить, это удаление / снятие отметки с элемента

вот мой рендер

    // Data is a service a created from which i get the data

    {
      Data.specialities.map(category => (
        <TouchableOpacity key={ category.value } onPress={ () => this.check(category) } style={ styles.list_container }>
          <View style={ styles.icon_container }>
            {
              this.state[category.value]
              ? <Icon name="md-checkmark" style={ styles.icon } />
              : null
            }
          </View>
          <Text style={ styles.category }>{ category.value }</Text>
        </TouchableOpacity>
      ))
    }

а вот и функция

check = async (e) => {

let selected = this.state.categories.map(category => {
  if (category.value == e.value) {
    let remove = this.state.categories.filter(cat => cat.value != e.value)
    this.setState({ categories: remove })
    return;
  } else {
    this.setState(prev => ({ categories: [ ...prev.categories, e ], [e.value]: !prev[e.value] }) )
  }
})
}

кажется, что else утверждение является истинным условием всегда!

0 ответов

Другие вопросы по тегам