我正在創建一個登錄組件,它將顯示登錄錯誤。 但我不知道如何把errors
陣列從_onSubmit
功能LoginForm
創建一個登錄組件,它將顯示登錄錯誤
這裏我的代碼。
import React, { Component } from 'react';
import Split from 'grommet/components/Split';
import Section from 'grommet/components/Section';
import Sidebar from 'grommet/components/Sidebar';
import LoginForm from 'grommet/components/LoginForm';
//import Logo from './Logo';
import firebase from 'firebase';
export default class Login extends Component {
constructor() {
super();
this._onSubmit = this._onSubmit.bind(this);
this._onResponsive = this._onResponsive.bind(this);
this.state = {responsive: 'multiple',errors:[]};
}
_onSubmit(fields) {
firebase.auth().signInWithEmailAndPassword(fields.username, fields.password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
var errors = [];
errors.push(errorCode);
errors.push(errorMessage);
console.log(errors);
// How to bring the errors from here to ??????
});
}
_onResponsive(responsive) {
this.setState({responsive: responsive});
}
render() {
var image;
if ('multiple' === this.state.responsive) {
image = <Section full={true} pad="none" texture="url(img/grafitti.jpg)" />;
}
return (
<Split flex="left" separator={true} onResponsive={this._onResponsive}>
{image}
<Sidebar justify="center" align="center" pad="medium" size="large">
<LoginForm
title="Ferret"
onSubmit={this._onSubmit}
errors={??????} />
</Sidebar>
</Split>
);
}
}
有人可以指導嗎?謝謝!!!
這是什麼編程語言? –
這不是一個好的架構,請考慮使用Redux代替,從演示組件分派動作以更新存儲中的應用程序狀態,執行異步動作 – RMontes13