Возможное необработанное отклонение обещания (id 0). Ошибка типа this.setstate не является функцией. - PullRequest
0 голосов
/ 06 января 2019

У меня ошибка, когда я пытаюсь получить значки, использую библиотекуact-native-vector-icons. Я прочитал всю документацию по библиотеке и попробовал их пример, но ничего.

class AuthScreen extends Component {
   constructor(props){
      super(props);
      this.state = {
          userIcon: "",
          lockIcon: ""
     }
  };
  render () {
     return (        
             <View style={styles.container}>
              <TextInput
                 placeholder="Usuario"
                 style={styles.InputContainer}
                 placeholderTextColor="#EEE"
                 inlineImageLeft={this.state.userIcon}
             />
               <TextInput
                 placeholder="Contraseña"
                 secureTextEntry={true}
                 style={styles.InputContainer}
                 placeholderTextColor="#EEE"
                 inlineImageLeft='search_icon'
                 inlineImageLeft={this.state.lockIcon}
              />             
              </View>
        ); 
    }
} 
Promise.all([
    Icon.getImageSource("md-person", 30),
    Icon.getImageSource("md-lock", 30)
]).then( sources => 
    this.setState({ 
        userIcon: sources[0],
        lockccccIcon: sources[1]  
    })
);

1 Ответ

0 голосов
/ 06 января 2019

вам нужно разрешить ваше обещание в componentDidMount или в любой функции, которая связана с «this» в конструкторе.

componentDidMount(){
    Promise.all([
        Icon.getImageSource("md-person", 30),
        Icon.getImageSource("md-lock", 30)
    ]).then( sources => 
        this.setState({ 
            userIcon: sources[0],
            lockccccIcon: sources[1]  
        })
    );
}
...