Reactjs Can';t使用状态将输入值从formik传递到post api

Reactjs Can';t使用状态将输入值从formik传递到post api,reactjs,react-native,fetch-api,formik,Reactjs,React Native,Fetch Api,Formik,}) 问题1:Web开发人员未在api中设置响应。所以我没有得到数据。在返回响应后,我能够获得用户通过表单提交的数据 问题2: 现在我得到了回复。我用的是国家。就我而言 const postCustomer = (formData) => { fetch(`${apiUrl.baseURL}post_customer.php`, { method: "POST", headers: { Accept: "application/json&quo

})

问题1:Web开发人员未在api中设置响应。所以我没有得到数据。在返回响应后,我能够获得用户通过表单提交的数据

问题2: 现在我得到了回复。我用的是国家。就我而言

const postCustomer = (formData) => {
fetch(`${apiUrl.baseURL}post_customer.php`, {
  method: "POST",
  headers: {
    Accept: "application/json",
    "Content-Type": "multipart/form-data",
  },
  body: formData, // This is working but for this values are not appearing on run-time.
  //body: profileItems,   This is not working.
})
  .then((response) => response.json())
  .catch((error) => {
    console.error(error);
    throw error;
  });
我在currentProfileItems中复制了profileItems。通过json设置相应的值后。我设法在运行时更改状态

const [profileItems, setProfileItems] = useState([]);

为什么不能只是
postCustomer(values)
?尝试什么都不发生。你说的状态变量是什么意思?我认为
profileItems
不是
FormData
对象。@Shyam const[profileItems,setProfileItems]=useState();
const [profileItems, setProfileItems] = useState([]);
try {
  const response = await fetch(`${apiUrl.baseURL}get_customer.php`);
  const json = await response.json();
  if (json.error === true) {
    console.log(json.error_msg);
  } else {
    setProfileImage(json.image);

    //make copy of original array
    let currentProfileItems = [...profileItems];

    // performing operations on copyied array
    currentProfileItems[0].value = json.name;
    currentProfileItems[1].value = json.phoneNo;
    currentProfileItems[2].value = json.email;
    currentProfileItems[3].value = json.address;

    // setting the new state
    setProfileItems(currentProfileItems);
  }
} catch (error) {
  console.log(error);
}