Hi Team
I need help, i am getting this issue basically i created a local data using localhost and helper class. When i launch this i get this exception and cant seem to solve it. the problem is on line 9 "Sidebar.js"
What I have tried:
//httpHelper.js
export const httpHelper =() => {
const customFetch = async(url, options = {})=>{
const defaultMethod = "GET"
const defaultHeaders = {
"Content-Type": "application/json",
Accept: "application/json",
}
const controller = new AbortController()
options.signal = controller.signal
options.method = options.method || defaultMethod
options.headers = options.headers
? { ...defaultHeaders, ...options.headers }
: defaultHeaders
options.body = JSON.stringify(options.body) || false
if (!options.body) delete options.body
setTimeout(() => {
controller.abort()
}, 3000)
try {
const response = await fetch(url, options)
return await response.json()
} catch (err) {
return err
}
}
const get = (url, options = {}) => customFetch(url, options)
const post = (url, options) => {
options.method = "POST"
return customFetch(url, options)
}
return{
get, post
}
}
// Sidebar.js
import { Sidebar } from '@coreui/coreui';
import React,{Component, useEffect, useState} from 'react';
import {httpHelper} from "./helpers/HttpHelper"
export default Sidebar =() => {
const Products=()=>{
const[product, setProducts] = useState(null)
const url = "http://localhost:3000/product"
const api = httpHelper()
useEffect(()=>{
getProducts()
}, [])
const postProducts = product=>{
api
.post('${url}', {body:product})
.then(response=>getProducts())
.catch(err=>console.log(err))
}
const getProducts =() =>{
api
.get('${url}?_expand=shipping')
.then(response=> {
getProducts(response)
}).catch(err=>console.log(err))
}
if(!product) return null
}
}