I want to fetch my local API. Please help. Here'a the code of my function:
const [data, setData] = useState(null);
async function fetchData() {
const response = await fetch("https://localhost:44344/homeApi", {
mode: "no-cors"
});
setData(await response.json());
}
here's the error in Concole:
// pointing to this line => setData(await response.json());
Uncaught (in promise) SyntaxError: Unexpected end of input
at fetchData (DataComponent.js:11:1)
fetchData @ DataComponent.js:11
await in fetchData (async)
(anonymous) @ DataComponent.js:15
invokePassiveEffectCreate @ react-dom.development.js:23487
callCallback @ react-dom.development.js:3945
invokeGuardedCallbackDev @ react-dom.development.js:3994
invokeGuardedCallback @ react-dom.development.js:4056
flushPassiveEffectsImpl @ react-dom.development.js:23574
unstable_runWithPriority @ scheduler.development.js:468
runWithPriority$1 @ react-dom.development.js:11276
flushPassiveEffects @ react-dom.development.js:23447
(anonymous) @ react-dom.development.js:23324
workLoop @ scheduler.development.js:417
flushWork @ scheduler.development.js:390
performWorkUntilDeadline @ scheduler.development.js:157