score:1
Accepted answer
in your deletemeal action, you have to put the id in the url dynamically with template strings,
await fetch("/api/meals/:id/" + id
1) it's equal to /api/meals/:id/id but according to your backend it should be /api/meals/:id
2) and you have to put the whole url like http://localhost:5000/api/meals/${id} cause if you don't put the base, it will do a request on the port of your client so 3000
///////
so instead of :
export const deletemeal = (id) => async (dispatch) => {
await fetch("/api/meals/:id/" + id, {
method: "delete",
});
dispatch({
type: delete_meal,
payload: id,
});
};
try this :
export const deletemeal = (id) => async (dispatch) => {
await fetch(`http://localhost:5000/api/meals/${id}/`, {
method: "delete",
});
dispatch({
type: delete_meal,
payload: id,
});
};
Source: stackoverflow.com
Related Query
- Delete item from MongoDB using React, Redux and Express
- Can't delete data (doc) from Firebase collection when using Redux and React
- How to execute store.unsubscribe from useEffect using React hooks and Redux
- How can I cache data that I already requested and access it from the store using React and Redux Toolkit
- Download file from Express API using React and Axios
- Delete node from Firebase using React and firereact
- Deleting an item from a collection in f, using React Redux
- How to update the global state using redux and remove an item from the global state
- How do I display data from api using react and redux
- React Redux store not updating on delete of an item from state
- Selecting random item from Javascript .filter() using React and Mongoose
- I want to delete an item from my list using a checkbox with react
- How to filter and delete an item by using redux toolkit
- How to delete data from server and UI using React and Node?
- How to properly encrypt and decrypt passwords using React MongoDB and Express
- Deleting Item from an array and rendering using React Hooks
- how to delete data from react crud using node js to mongoDB
- Delete a row from a table using and Id React
- Delete item from data in reactjs and redux
- Delete Item inside an Array of an Array in React and Redux
- How do I render a list from Json data in express js, then render it using react and map()?
- How to POST and GET from mongoDB express server in react hooks?
- Using values from previously dispatched action in the next action in React and Redux
- How remove item from redux state using react hooks
- trying to delete from an API using axios and React hooks
- Need to delete item from array using redux
- How to send a form input data containing both image and text from React front-end to Express backend using Multer
- Updating lists on FrontEnd from MongoDB using mongoose and react
- How to implement Axios.delete in react and delete from Mongodb by id
- Parsing JSON's from a server using React and Express - "TypeError: Cannot read property '' of undefined"
More Query from same tag
- Double spread problem - getting rid of Object.assign()
- Cronjob in react JS
- I am trying to build a vertical mousewheel control swiper in react.js but it is not working?
- React Router v6 not showing nested route - what am I missing?
- React Hooks - share parent state with multiple dynamic components
- GET http://localhost:3000/search 404 (Not Found)REACT.JS, Node.js and Axios
- Next js:- Reload Image even src path is same using setState
- How to change routes in gatsby without Link component?
- Sending a request from react to express using CKEDITOR 5
- Reactjs - getting data from server and updating
- Why child Styled-components is not applying styles?
- Button 'more' in a popup box doesn’t work right with React hook useState
- React, can't set new data after get from api
- Slug that isn't whole file name in Next.js?
- How to combine react-i18next with Semantic UI label tag?
- Not able to mock a function inside useEffect
- How to update inner nested object property
- Interacting with React components from non-react world
- Redirect All URL's With A Particular Pathname To A Certain View - LARAVEL
- useMemo hook always True even the location.pathname change
- Redirection In React-Router-Dom v6
- How to change state immediately and then change back to empty after a delay using UseState?
- Make a div on top of all the others
- REACT: How to swap elements in To Do list by their priorities
- Delete item from table React
- Cannot set defaultValue in React-Select
- firebase.auth is not a function
- Having a problem loading in data to child component in react
- Build is successful in Jenkins but AWS-Codebuild is giving plugin error
- Can't scroll while using pointer-events: auto; property