Meu app React Native
é gerenciado pelo Redux
. Preciso executar a função _verificaLogin()
vinda pelo connect
automaticamente quando meu app é renderizando. Do modo que fiz não esta funcionando, acho que a props
não recebeu a função ainda quando eu faço a chamada pelo componentDidMount
.
segue o codigo:
class Login extends React.Component { constructor(props) { super(props); this.state = { email: '', senha: '' }; } componentDidMount() { this._verificaLogin(); } _verificaLogin() { const { email, senha } = this.state; this.props.verificaLogin(); } render() { return ( <View style={ styles.container }> <StatusBar backgroundColor={ '#303F9F' } /> <TextInput style={ styles.input } placeholder={ "Email" } value={ this.state.email } onChangeText={ email => this.setState({ email }) }/> <TextInput style={ styles.input } placeholder={ "Senha" } value={ this.state.senha } onChangeText={ senha => this.setState({ senha })}/> <Text style={{ color: 'red', height:45 }}>{ this.props.message }</Text> <View style={{ marginTop: 24 }}> <View style={ styles.bt }> <Button style={ styles.input } title={ "ENTRAR" } color={ '#3f51b5' } onPress={ () => this._verificaLogin() }/> </View> <View style={ styles.bt }> <Button style={ styles.input } title={ "ATIVAR CONTA" } color={ '#747474' } onPress={ () => Actions.ativar() }/> </View> <TouchableHighlight style={{ marginTop: 16, alignItems: 'center' }} onPress={ () => false }> <Text style={{ color: '#e5625d' }}>Esqueci minha senha</Text> </TouchableHighlight> </View> </View> ); }
}
const mapStateToProps = state => ({ message: state.LoginReducer.message });
export default connect(mapStateToProps, { verificaLogin })(Login);