【发布时间】:2020-01-10 11:32:21
【问题描述】:
所以我终于了解了使用 Redux 的 Flux 架构(我将每个函数与操作连接起来并从那里调用服务)
目前我有这个问题:
我的组件状态:
this.state = {
username: '',
counter: '',
email: '',
buttonText: 'textbefore',
}
我在这个组件中有函数(我在其中调度操作):
handleSubmit(e) {
e.preventDefault()
if(username && email) {
this.props.dispatch(eventActions.save(username, email))
}
else {
this.props.dispatch(alertActions.warn("Wystąpił błąd"))
this.props.dispatch(viewActions.hide())
}
}
这是行动:
function save(username, email) {
return dispatch => {
eventService.signUp({username, email})
.then(
response => {
dispatch(alertActions.success("text))
},
error => {
dispatch(alertActions.error(error))
}
)
}
}
这是常量:
export const eventConstants = {
SIGNUP_REQUEST: 'EVENT_SIGNUP_REQUEST',
SIGNUP_SUCCESS: 'EVENT_SIGNUP_SUCCESS',
SIGNUP_FAILURE: 'EVENT_SIGNUP_FAILURE',
}
这是减速器:
import { eventConstants } from '../constants/event.constants'
export default function event(state={}, action){
switch(action.type){
case eventConstants.SIGNUP_REQUEST:
return{...state, ...{}}
case eventConstants.SIGNUP_SUCCESS:
return{...state, ...{}}
case eventConstants.SIGNUP_FAILURE:
return{...state, ...{}}
}
}
我的问题是:
发送成功后如何将buttonText的状态从'textbefore'更改为'textafter'?
我有函数,哪个resetForm,我在哪里可以从redux架构调用它?
resetForm = () => {
this.setState({
name: '',
message: '',
email: '',
buttonText: 'Wiadomość wysłana'
})
}
- 如何处理和支持错误?
【问题讨论】:
标签: reactjs redux action reducers