本机可能未处理的承诺拒绝TypeError:无法将null或undefined转换为object

时间:2017-10-01 21:46:00

标签: react-native promise redux

我一直收到这个警告:

Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
    at Function.from (native)
    at Object.babelHelpers.toConsumableArray (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:1222:18)
    at exports.default (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:54625:66)
    at combination (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:54044:29)
    at dispatch (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:53680:22)
    at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:54511:16
    at dispatch (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:54140:18)
    at _callee2$ (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:74948:81)
    at tryCatch (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:10369:40)
    at Generator.invoke [as _invoke] (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:10557:22)

我的行动是这样的:

export const createPost = (post) =>
        async (dispatch) => {
                const response = await PostAPI.createPost(post);
                await dispatch({ type: CREATE_POST, payload: response });
        };

我的减速机是这样的:

        case CREATE_POST:
                return {
                        ...state,
                        postList: [...state.arr, action.payload]
                };

我的api电话是这样的:

static async createPost(post) {
        const api = '';
        try {
                const response = await fetchApi(
                        postUrl + api,
                        'POST',
                        JSON.stringify(post)                                
                );
                return await response.json();
        } catch (error) {
                throw error;
        }
}

事件调用是这样的:

onPostPress() {
        const { caption } = this.props;
        this.props.createPost({
                text: caption,
                pictures: null,
                parentId: null,
                action: 'Post'
        });
        Actions.pop();
}

我已经在PostMan中测试了我的API调用,它运行正常。

0 个答案:

没有答案