【发布时间】:2021-09-13 09:21:47
【问题描述】:
我正在尝试存储是否已验证电话号码的布尔值。
在我的登录组件中:
await dispatch(setOTPVerified(data.is_phone_verified));
Action.tsx:
export const OTP_VERIFIED = 'OTP_VERIFIED';
export const setOTPVerified = (OTPVerified: boolean) => {
return {
type: OTP_VERIFIED,
OTPVerified,
};
};
Reducer.tsx:
export interface ExtrasParams {
OTPVerified?: any;
}
const initialData: ExtrasParams = {
OTPVerified: false,
};
const extrasReducer = (state = initialData, action: any): ExtrasParams => {
switch (action.type) {
case OTP_VERIFIED:
state = {...state, OTPVerified: action.OTPVerified};
return state;
default:
return state;
}
};
Saga.tsx:
function* getOTPVerified(action: any) {
yield put({
OTPVerified: action.OTPVerified,
});
}
export default function* extrasSaga() {
yield takeLatest(OTP_VERIFIED, getOTPVerified);
}
控制台错误:
Error: Actions may not have an undefined "type" property. Have you misspelled a constant?
The above error occurred in task getOTPVerified
created by takeLatest(OTP_VERIFIED, getOTPVerified)
我是在 react native 中使用 typescript 的新手,在 redux 中声明类型不是很清楚。我一直在尝试不同的类型,但我无法清除此错误。
【问题讨论】:
标签: typescript react-native redux react-redux redux-saga