542 viewsMern Amazona

Hello Basir  ,

I had a problem to fetch the data from the backend since i am using Vite instead of create-react-app , i solved this problem by changing the proxy params in vite.config.js file instead of the proxy in package.json .

Then , when i tried to implement useReducer EXACTLY like you did , the loading message was appearing .
I’ve tried to debug it and understood that the function fetchData was not even called once and i don’t understand why …

Here’s my vite.config :

import { defineConfig } from ‘vite’
import react from ‘@vitejs/plugin-react’
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
host:true,
port:3000,
proxy: {
‘/api/products’: {
target:’http://localhost:8000′,
changeOrigin:true,
secure:false,
},
},
},
})

Bassir Posted new comment March 10, 2023

Great, you fix the issue

Bassir Answered question March 9, 2023

for vite I suggest to use this code:

https://github.com/basir/ts-mern-amazona/blob/main/frontend/src/main.tsx#L17

Bassir Answered question March 9, 2023