在没有任何其他附加库的情况下,在CREATE_ACCOUNT操作被分派之后,从redux-store中清除account、image、name状态的最简单方法是什么?
import { CREATE_ACCOUNT } from '../actions/meals'
const initialState = {
account: [],
image:[],
name:''
}
const addPerson = (state=initialState, action) =>{
switch(action.type){
case CREATE_ACCOUNT:
const newAccount = new newAccount(
Date.now().toString(),
action.accountData.name,
action.accountData.image,
action.accountData.email,
action.accountData.password
)
return {account: state.account.concat(newAccount) }
default:
return state
}
}
export default addPerson发布于 2020-07-21 21:35:26
最简单的方法是添加另一个案例进行切换,如下所示:
const reducer = (state=INITIAL_STATE, action) {
switch(action.type) {
case 'SOME_ACTION_TYPE':
// some code
case "RESET":
return INITIAL_STATE;
default:
return state;
}
}现在,如果您将action.type设置为'RESET‘,您实际上是在清除数据。
发布于 2020-07-21 21:36:38
如果没有额外的库,我现在不能工作,但你可以尝试一下:
const mapDispatchToProps = (dispatch, { navigation }) => {
return {
function: () => dispatch(FirstAction(params)).then(() => dispatch({ type: 'NextActionToDispatch' }))
};
};https://stackoverflow.com/questions/63015083
复制相似问题