How does a React app call an Express API?
Model answer
With fetch or axios from an event handler or effect (or TanStack Query): fetch('/api/jobs'). During development a Vite proxy forwards /api to the Express port to avoid CORS. In production, serve both from the same domain or enable CORS with a specific allowed origin.
Learn this topic
useEffect and Fetching Data from Your API: Loading, Errors and Cleanup in the course MERN Stack Full Course: MongoDB, Express, React and Node.js.
Sign in to add your own answer.
More questions
- How do you set up a Vite proxy for development?
- How do you serve a React build from Express?
- How do you handle authentication state in a MERN frontend?
- How do you handle loading, error and empty states for API data in React?
- How do you build a dashboard with filters and pagination backed by the API?
- How do you share validation and types between frontend and backend?