Реагировать на собственный флажок - PullRequest
0 голосов
/ 09 декабря 2018

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

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

    // 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 всегда является истинным условием!

...