我正在尝试在react redux中设置两个单独的uPort登录的状态。我已经尝试过在下面进行操作,但是出现错误
未处理的拒绝(TypeError):_this.props.actions.connectUportDoc 不是功能
我想基本上创建一个if else语句。如果按下患者按钮,请按下以确认LoginPatient。如果按下了医生按钮,请按以确认LoginDoctor。
class Login extends Component {
constructor(props) {
super(props)
// this.connectUport = this.connectUport.bind(this)
this.connectUportDoc = this.connectUportDoc.bind(this)
this.connectUportPatient = this.connectUportPatient.bind(this)
uportConnect.onResponse(ConnectReqID).then((res) => {
console.log('res.payload')
console.log(res.payload)
this.props.actions.connectUportDoc(uportConnect.state)
this.props.history.push('/confirmLoginDoctor')
})
uportConnect.onResponse(ConnectReqID).then((res) => {
console.log('res.payload')
console.log(res.payload)
this.props.actions.connectUportPatient(uportConnect.state)
this.props.history.push('/confirmLoginPatient')
})
}
connectUportDoc() {
const reqObj = {
requested: ['name', 'phone', 'country', 'avatar', 'email'],
notifications: true,
}
console.log(reqObj)
uportConnect.requestDisclosure(reqObj, ConnectReqID)
}
connectUportPatient() {
const reqObj = {
requested: ['name', 'phone', 'country', 'avatar', 'email'],
notifications: true,
}
console.log(reqObj)
uportConnect.requestDisclosure(reqObj, ConnectReqID)
}
render() {
return (
<a onClick={this.connectUportDoc.bind(this)}>Doctor Login</a>
<a onClick={this.connectUportPatient.bind(this)}>Patient Login</a>
)
}
}
const mapStateToProps = (state, props) => {
return {
uport: state.login.uport,
}
}
const mapDispatchToProps = (dispatch) => {
return { actions: bindActionCreators(AppActions, dispatch) }
}
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(Login)
)