有没有办法取消行动或忽略它?
或者更确切地说,忽略行动的最佳/推荐方法是什么?
我有以下动作创建者,当我向动作创建者输入无效大小(比如说'some_string')时,除了获取我自己的警告信息外,我还得到:
Uncaught Error: Actions must be plain objects. Use custom middleware for async actions.
import { SET_SELECTED_PHOTOS_SIZE } from './_reducers';
export default (size=0) => {
if (!isNaN(parseFloat(size))) {
return {
type: SET_SELECTED_PHOTOS_SIZE,
size: size,
};
} else {
app.warn('Size is not defined or not a number');
}
};
Run Code Online (Sandbox Code Playgroud)
我redux在Discord(reactiflux)中的-channel中讨论了这个问题,其中一个建议是使用如下的redux-thunk:
export default size => dispatch => {
if (!isNaN(parseFloat(size))) {
dispatch({
type: SET_SELECTED_PHOTOS_SIZE,
size: size,
});
} else {
app.warn('Size is not defined or not …Run Code Online (Sandbox Code Playgroud)