javascript 错误指出不是函数,但它确实是函数

kqlmhetl  于 2023-02-07  发布在  Java
关注(0)|答案(1)|浏览(80)

我希望有人能帮我找出我做错了什么。我在一个React组件AddProject中有一些代码,看起来像这样。

import React, { useState, useContext } from "react";
import "./addproject.css";
import UserContext from "../../UserContext";
import saveProject from '../../features/saveProject';

function AddProject() {

    const handleSaveProject = () => {

        const projectData = {

        [userEmail]: {
            clientName: clientName,
            clientEmail: clientEmail,
            stages: stages,
        }
    }

    console.log(userEmail, projectData);

    saveProject(projectData)
//etc

我还有另一个组件/方法saveProject,我想向它传递一些 prop ,并使用Axios发出发布请求。

import React, { useState } from "react";
import axios from "axios";

const saveProject = (projectData) => {

    const handleSubmit = (event) => {

        event.preventDefault();

        axios

            .post("[http://localhost:4000/users](http://localhost:4000/users)", projectData)
            .then((res) => console.log(res))
            .catch((err) => console.error(err));

    };

    return (null);
};

export default saveProject;

我一直收到这个错误,告诉我它不是一个函数。我尝试将import语句更改为{saveProject}并改为export const,但没有帮助。ChatGPT也无法解决这个问题。有什么想法吗?

2AddProject.jsx:86 Uncaught TypeError: _features_saveProject__WEBPACK_IMPORTED_MODULE_3___default(...) is not a function
at handleSaveProject (AddProject.jsx:86:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
at invokeGuardedCallback (react-dom.development.js:4056:1)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070:1)
at executeDispatch (react-dom.development.js:8243:1)
at processDispatchQueueItemsInOrder (react-dom.development.js:8275:1)
at processDispatchQueue (react-dom.development.js:8288:1)
at dispatchEventsForPlugins (react-dom.development.js:8299:1)
at react-dom.development.js:8508:1
46scxncf

46scxncf1#

想明白了,不知怎么的没保存,没做什么的,就是没导出,重启服务器也没用,但是重启电脑的时候,不知什么原因显示错误,谢谢大家

相关问题