if you know react (using context api) ,you can look into my issue
this is my github repo : https://github.com/nareshkumar1201/todo-react
i am facing issue , where i wanted to update/toggle the completed property in todo list ---
present state of the app is that -one can add todo ,delete todo , and now i am working on the checkbox -on click of checkbox it should update the completed property in todo list , issue is that when i click on checkbox for the first time it is working fine but if is select/uncheck the todo for the 2nd time its not working ... i don,t know where i am going wrong ??
it will a great help if some one look into issue
import React, { Fragment, useContext } from "react";
import PropTypes from "prop-types";
import TodoContext from "../context/TodoContext";
const TodoItem = ({ todo }) => {
// console.log(todo);
const todoContext = useContext(TodoContext);
const { deleteTodo, updateTodo } = todoContext;
// const { id, todo, completed } = todo;
**const onChange = (e) => {
console.log("todoItem: update req", todo.id);
updateTodo(todo.id);
};**
const onClick = () => {
console.log("todoItem: delete req", todo.id);
deleteTodo(todo.id);
};
return (
<Fragment>
<div className="container col-12 todo-item-container">
<ul className="list-group w-100">
<li className="list-group-item">
**<input
type="checkbox"
name="todo"
// value={todo.todo}
onChange={onChange}
/>**
<span className="text-info"> {todo.todo}</span>
<button className="btn float-right ">
<i
className="fa fa-pencil-square-o text-info "
aria-hidden="true"
></i>
</button>
<button className="btn float-right" onClick={onClick}>
{" "}
<i className="fa fa-trash text-info" aria-hidden="true"></i>
</button>
</li>
</ul>
</div>
</Fragment>
);
};
TodoItem.propTypes = {
todo: PropTypes.object.isRequired,
};
export default TodoItem;
This is state:
import React, { useReducer } from "react";
import TodoContext from "./TodoContext";
import TodoReducer from "./TodoReducer";
import { v1 as uuid } from "uuid";
import {
ADD_TODO,
EDIT_TODO,
DELETE_TODO,
DISPLAY_TODOS,
UPDATE_TODO,
} from "./types";
const TodoState = (props) => {
const initialState = {
todos: [
{
id: 1,
todo: "Do cook food",
completed: false,
},
{
id: 2,
todo: "Clean Room",
completed: false,
},
{
id: 3,
todo: "Wash Car",
completed: false,
},
],
};
const [state, dispatch] = useReducer(TodoReducer, initialState);
//add todo
const addTodo = (todo) => {
todo.id = uuid();
console.log(todo);
// todo.completed = false;
dispatch({ type: ADD_TODO, payload: todo });
};
//display todo
const displayTodos = () => {
dispatch({ type: DISPLAY_TODOS, payload: state.todos });
};
//edit todo
//delete todo
const deleteTodo = (id) => {
console.log("payload id", id);
dispatch({ type: DELETE_TODO, payload: id });
};
//update todo
**const updateTodo = (id) => {
console.log("in todoState", id);
dispatch({ type: UPDATE_TODO, payload: id });
};**
return (
<TodoContext.Provider
value={{
todos: state.todos,
addTodo,
displayTodos,
deleteTodo,
updateTodo,
}}
>
{props.children}
</TodoContext.Provider>
);
};
export default TodoState;
This is reducer:
import {
ADD_TODO,
EDIT_TODO,
DELETE_TODO,
DISPLAY_TODOS,
UPDATE_TODO,
} from "./types";
// import todoContext from "./TodoContext";
const TodoReducer = (state, action) => {
switch (action.type) {
case ADD_TODO:
return {
...state,
todos: [...state.todos, action.payload],
};
case DISPLAY_TODOS:
return {
...state,
todos: action.payload,
};
case DELETE_TODO:
return {
...state,
todos: state.todos.filter((todoObj) => todoObj.id !== action.payload),
};
**case UPDATE_TODO:
console.log("in reducer :", action.payload);
return {
...state,
todos: state.todos.map((todoObj) => {
if (todoObj.id === action.payload) {
todoObj.completed = !todoObj.completed;
}
return todoObj;
}),
};**
default:
return state;
}
};
export default TodoReducer;
Screen images:on click on checkbox for the first time -working fine
if click on 2nd todo checkbox its not working
There was issue with your return in UPDATE_TODO.
I have fixed same for you, Do test and let me know.
While making changes to the object in todos array you need to copy it using the spread operator and then make changes and then return the object.
case UPDATE_TODO:
console.log("in reducer :", action.payload);
return {
...state,
todos: state.todos.map((todoObj) => {
if (todoObj.id === action.payload) {
return { ...todoObj, completed: !todoObj.completed };
}
return todoObj;
}),
};
Related
I using Context.Provider + useReducer, i have function "fetchCars()" in my context for fetching cars which depends on selected filter value
May be noob question, but i can't understand why consumer-component named "Filters.jsx" is mounting every time after i changed filter value. And because of this i cant save values in useState of Filter.jsx component
Codesandbox link
https://codesandbox.io/s/peaceful-morse-21zj6m?file=/src/components/Filters.jsx
in Codesandbox you can see console print when filter changed
CarsContextProvider.jsx
import { useReducer, createContext, useCallback } from "react";
export const CarsContext = createContext()
const getCarsFromServer = (status) => {
// dummy fetch
const dataFromServer = [
{ id: 1, name: 'Volvo', status: 'notAvailable' },
{ id: 2, name: 'BMW', status: 'inStock' },
{ id: 3, name: 'Mercedes', status: 'notAvailable' },
{ id: 4, name: 'Audi', status: 'notAvailable' },
{ id: 5, name: 'Opel', status: 'inStock' },
{ id: 6, name: 'Renault', status: 'inStock' },
]
return new Promise((resolve) => {
setTimeout(() => {
if (status === 'all') {
return resolve(dataFromServer)
}
resolve(dataFromServer.filter(item => item.status === status))
}, 500);
})
}
const reducer = (state, action) => {
switch (action.type) {
case 'pending':
return { ...state, loading: true }
case 'success':
return { ...state, loading: false, items: action.payload }
case 'error':
return { ...state, loading: false, error: action.payload }
case 'setFilter':
return { ...state, statusFilter: action.payload }
default:
break;
}
}
const initState = {
items: [],
loading: false,
error: '',
statusFilter: 'all',
}
const CarsContextProvider = ({ children }) => {
const [state, dispatch] = useReducer(reducer, initState)
const fetchCars = useCallback(async () => {
try {
dispatch({ type: 'pending' })
const data = await getCarsFromServer(state.statusFilter)
dispatch({ type: 'success', payload: data })
} catch (error) {
dispatch({ type: 'error', payload: error })
}
}, [state.statusFilter])
return (
<CarsContext.Provider value={{ state, dispatch, fetchCars }}>
{children}
</CarsContext.Provider>
)
}
export default CarsContextProvider
App.jsx
import CarsScreen from "./components/CarsScreen";
import CarsContextProvider from "./context/CarsContext";
function App() {
return (
<CarsContextProvider>
<CarsScreen />
</CarsContextProvider>
);
}
export default App;
CarsScreen.jsx
import CarsList from "./CarsList"
const CarsScreen = () => {
return (
<div>
<CarsList />
</div>
)
}
export default CarsScreen
CarsList.jsx
import { useContext, useEffect } from "react"
import { CarsContext } from "../context/CarsContext"
import Filters from "./Filters"
const CarsList = () => {
const { state, fetchCars } = useContext(CarsContext)
useEffect(() => {
fetchCars()
}, [fetchCars])
if (state.loading) return <h3>loading...</h3>
return (
<>
<Filters />
<hr />
<ul>
{state.items.map((car => <li key={car.id}>{car.name}</li>))}
</ul>
</>
)
}
export default CarsList
Filters.jsx
import { useState, useEffect, useContext } from "react"
import { CarsContext } from "../context/CarsContext"
const Filters = () => {
const [localState, setLocalState] = useState('init')
const { state, dispatch } = useContext(CarsContext)
useEffect(() => {
// There is my question! Why console.log executing every time i change filter select option ?
console.log('component mounted');
}, [])
const filterChangeHandler = (e) => {
//and also localState could not change, because this component every time mounts with init value
setLocalState('filter changed')
// this dispatch changes filter value, and items fetching from server
dispatch({ type: 'setFilter', payload: e.target.value })
}
return (
<div>
<select
name="stockFilter"
onChange={filterChangeHandler}
defaultValue={state.statusFilter}
>
<option value="all">show all</option>
<option value="inStock">in stock</option>
<option value="notAvailable">not available</option>
</select>
<p>Filters local state is : {localState}</p>
</div>
)
}
export default Filters
Codesandbox link
https://codesandbox.io/s/peaceful-morse-21zj6m?file=/src/components/Filters.jsx
Tried to comment React.StrictMode line in index.js., but no effect
Is it possible to avoid this unwanted mount Filters.jsx component?
Found a problem.
Problem was in component GoodsList.jsx loading status was dismounting Filter.jsx
if (state.loading) return <h3>loading...</h3>
fixed version of GoodsList.jsx
import { useContext, useEffect } from "react"
import { GoodsContext } from "../context/GoodsContextProvider"
import GoodsFilter from "./GoodsFilter"
const GoodsList = () => {
const { state, fetchGoods } = useContext(GoodsContext)
useEffect(() => {
fetchGoods()
}, [fetchGoods])
return (
<>
<GoodsFilter />
{state.loading ? <h3>loading...</h3>
:
<>
<hr />
<ul>
{state.items.map((good => <li key={good.id}>{good.name} - {good.quantity}</li>))}
</ul>
</>
}
</>
)
}
export default GoodsList
I am in the process of finishing my todo application, since redux is a bit new to me of course I encounter problems. My problem is when I click the delete button (recycle icon) I want a confirmation box to pop up with basic Yes and No buttons, I have built that, but... when I click one recycle button all of the other confirmation boxes get set to True and they pop up in sync. I need only one box to pop up for the right todo.id.
Note: I have built this before without redux, but I am still wrapping my head around redux.
Here is my code:
JS:
import React, {useState, Fragment} from 'react'
import { useDispatch, useSelector } from 'react-redux';
import "./todo.css"
const Todos = () => {
const dispatch = useDispatch();
const todos = useSelector(state => state.todos);
const confirmationSt = useSelector(state => state.confirmation)
const handleConfirm = id => {
dispatch({
type: "CONFIRM",
})
}
const handleContinue = () => {
dispatch({
type: "CONTINUE",
})
}
const handleClick = id => dispatch({
type: "DELETE_TODO",
payload: id,
})
if (!todos || !todos.length) {
return <p>Empty</p>
}
return (
<ul className='unlist'>{todos.map(todo =><Fragment key={todo.id}> <div className='todoContent'><li >{todo.label}</li>
<div><button className='delete' onClick={handleConfirm}><i className="fas fa-recycle"></i></button>
<button className='delete' onClick={handleConfirm}><i className="fas fa-wrench"></i></button>
</div>
</div>
{confirmationSt === true ? <div className='confirmation-box'>
Are you sure?
<button onClick={() => handleClick(todo.id)}>Yes</button>
<button onClick={handleContinue}>No</button>
</div> : null}
</Fragment>
)}
</ul>
)
}
Reducer:
const initalState = {
todos: [],
confirmation: false,
}
const reducer = (state = initalState, action) => {
switch (action.type) {
case "ADD_TODO":
return {
...state,
todos: [...state.todos, action.payload],
}
case "DELETE_TODO":
return {
...state,
todos: state.todos.filter(todo => todo.id !== action.payload)
}
case "CONFIRM":
return {
...state,
confirmation: !state.confirmation,
}
case "CONTINUE":
return {
...state,
confirmation: false
}
default: return state;
}
}
export default reducer
I have changed confirmation from boolean to id of the task
import React, { useState, Fragment } from 'react'
import { useDispatch, useSelector } from 'react-redux';
import "./todo.css"
const Todos = () => {
const dispatch = useDispatch();
const todos = useSelector(state => state.todos);
const confirmationSt = useSelector(state => state.confirmation)
const handleConfirm = id => {
dispatch({
type: "CONFIRM",
payload: id
})
}
const handleContinue = () => {
dispatch({
type: "CONTINUE",
})
}
const handleClick = id => dispatch({
type: "DELETE_TODO",
payload: id,
})
if (!todos || !todos.length) {
return <p>Empty</p>
}
return (
<ul className='unlist'>
{ todos.map(todo =>
<Fragment key={todo.id}>
<div className='todoContent'>
<li >{todo.label}</li>
<div>
<button className='delete' onClick={()=>handleConfirm(todo.id)}>
<i className="fas fa-recycle"></i>
</button>
<button className='delete' onClick={()=>handleConfirm(todo.id)}>
<i className="fas fa-wrench"></i>
</button>
</div>
</div>
{
confirmationSt === todo.id ?
<div className='confirmation-box'>
Are you sure?
<button onClick={() => handleClick(todo.id)}>Yes</button>
<button onClick={handleContinue}>No</button>
</div>
: null
}
</Fragment>
)}
</ul>
)
}
const initalState = {
todos: [],
confirmation: -1,
}
const reducer = (state = initalState, action) => {
switch (action.type) {
case "ADD_TODO":
return {
...state,
todos: [...state.todos, action.payload],
}
case "DELETE_TODO":
return {
...state,
todos: state.todos.filter(todo => todo.id !== action.payload)
}
case "CONFIRM":
return {
...state,
confirmation: action.payload,
}
case "CONTINUE":
return {
...state,
confirmation: false
}
default: return state;
}
}
export default reducer
I'm trying to learn the MERN stack, and I'm going through this tutorial on YouTube. I'm getting stuck in Ep. 7. The issue I think I'm having is my ADD_ITEM action is never triggered, and so the state is never updated, and I have to reload the page in order to see any items added. The DELETE_ITEM action works properly, so I suspect there may be an issue with the ADD_ITEM action being called from a form in a modal, but I'm unsure.
Picture of my Redux DevTools after refreshing the page, deleting 2 items, and trying to add 1:
itemReducer.js
import { GET_ITEMS, ADD_ITEM, DELETE_ITEM, ITEMS_LOADING } from '../actions/types';
const initialState = {
items: [],
loading: false
};
export default function(state = initialState, action) {
console.log(action.type);
switch(action.type) {
case GET_ITEMS:
return { ...state, items: action.payload, loading: false };
case ADD_ITEM:
return { ...state, items: [action.payload, ...state] };
case DELETE_ITEM:
return { ...state,
items: state.items.filter(item => item._id !== action.payload)
};
case ITEMS_LOADING:
return {
...state,
loading: true
};
default:
return state;
}
}
ItemModal.js
import React, { Component } from 'react';
import { Button, Modal, ModalHeader, ModalBody, Form, FormGroup, Label, Input } from 'reactstrap';
import { connect } from 'react-redux';
import { addItem } from '../actions/itemActions';
class ItemModal extends Component {
state = {
modal: false,
name: ''
}
toggle = () => {
this.setState({
modal: !this.state.modal
});
}
onChange = (e) => {
this.setState({ [e.target.name]: e.target.value })
}
onSubmit = (e) => {
e.preventDefault();
const newItem = {
name: this.state.name
}
this.props.addItem(newItem);
this.toggle();
}
render() {
return(
<div>
<Button
color="dark"
style={{marginBotton: '2rem'}}
onClick={this.toggle}
>Add Item</Button>
<Modal
isOpen={this.state.modal}
toggle={this.toggle}
>
<ModalHeader
toggle={this.toggle}
>
Add To Shopping List
</ModalHeader>
<ModalBody>
<Form onSubmit={this.onSubmit}>
<FormGroup>
<Label for="item">Item</Label>
<Input
type="text"
name="name"
id="item"
placeholder="Add shopping item"
onChange={this.onChange}
/>
</FormGroup>
<Button
color="dark"
style={{marginTop: '2rem'}}
block
>Submit</Button>
</Form>
</ModalBody>
</Modal>
</div>
)
}
}
const mapStateToProps = state => ({
item: state.item
});
export default connect(mapStateToProps, { addItem })(ItemModal);
itemActions.js
import axios from 'axios';
import { GET_ITEMS, ADD_ITEM, DELETE_ITEM, ITEMS_LOADING } from './types';
export const getItems = () => dispatch => {
dispatch(setItemsLoading());
axios.get('/api/items').then(res => dispatch({
type: GET_ITEMS,
payload: res.data
}))
};
export const deleteItem = (id) => dispatch => {
axios.delete(`/api/items/${id}`).then(res => dispatch({
type: DELETE_ITEM,
payload: id
}))
};
export const addItem = (item) => dispatch => {
axios.post('/api/items', item).then(res => dispatch({
type: ADD_ITEM,
payload: res.data
}))
};
export const setItemsLoading = () => {
return {
type: ITEMS_LOADING
};
};
currently working on adding the items to cart using react and redux but the add item does not work
I'm taking the items from my collections page and then passing the key to the product preview page
I'm using react-redux cartReducer the three files are
just can't figure out how to pass the fish products
product page
cart actions
cart reducer
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import firebase from '../../firebase/firebase';
import { connect } from 'react-redux';
import { addItem } from '../../redux/cart/cart-actions'
class FishPage extends Component {
constructor(props) {
super(props);
this.ref = firebase.firestore().collection('fishproducts');
this.unsubscribe = null;
this.state = {
fishproducts: []
};
}
componentDidMount() {
const ref = firebase.firestore().collection('fishproducts').doc(this.props.match.params.id);
ref.get().then((doc) => {
if (doc.exists) {
this.setState({
fishproducts: doc.data(),
key: doc.id,
isLoading: false
});
} else {
console.log("No such document!");
}
});
}
render() {
return (
<div >
<div>
<div>
<h4><Link to="/">back</Link></h4>
<h3>
{this.state.fishproducts.name}
</h3>
</div>
<div >
<dl>
<dt>Description:</dt>
<dd>{this.state.fishproducts.description}</dd>
<dt>Discount:</dt>
<dd>{this.state.fishproducts.discount}</dd>
<dt>Size:</dt>
<dd>{this.state.fishproducts.size}</dd>
<dt>Weight:</dt>
<dd>{this.state.fishproducts.weight}</dd>
<dt>Price:</dt>
<dd>{this.state.fishproducts.price}</dd>
<dt>Stock:</dt>
<dd>{this.state.fishproducts.stock}</dd>
</dl>
<button onClick={() => addItem(this.state.fishproducts)} >ADD TO CART</button>
</div>
</div>
</div>
);
}
}
const mapDispatchToProps = dispatch => ({
addItem: item => dispatch(addItem(item))
})
export default connect(null, mapDispatchToProps)(FishPage);```
this is cart action page
```import CartActionTypes from './cart-types';
export const toggleCartHidden = () => ({
type:CartActionTypes.TOGGLE_CART_HIDDEN
});
export const addItem = item => ({
type: CartActionTypes.ADD_ITEM,
payload: item
})```
this is cart reducer
```import CartActionTypes from './cart-types';
const INITIAL_STATE = {
hidden: true,
cartItems: []
};
export const cartReducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
case CartActionTypes.TOGGLE_CART_HIDDEN:
return {
...state,
hidden: !state.hidden
};
case CartActionTypes.ADD_ITEM:
return {
...state,
//cartItems: addItem(state.cartItems, action.payload)
cartItems: [...state.cartItems,action.payload]
};
default:
return state;
}
}
export default cartReducer;```
cant figure out how to pass fishproducts
So concept of React is that you need to access Firebase with a function. For that you should use a functional component.
React allows Hooks to get access to your state without a constructor so that's all
and then you'll need to use dispatch.
import React, { useState, useEffect } from 'react';
import firebase from '../../firebase/firebase';
import { Link } from 'react-router-dom';
import { connect , useDispatch} from "react-redux";
import { addItem} from '../../redux/cart/cart-actions';
const FishPage = (props) => {
const [state, setState] = useState({
name: '',
… rest of the values
isLoading: true,
})
const { name, … rest of the values } = state;
useEffect(() => {
setState({ isLoading: true });
const ref = firebase.firestore().collection('fishproducts').doc(props.match.params.id);
ref.get().then((doc) => {
setState({
name: doc.data().name,
… rest of the values
isLoading: false,
});
})
}, [props.match.params.id])
const item = [];
const dispatch = useDispatch();
return (
<div >
<div>
//your body here
<button onClick={() => dispatch(addItem(item))} >ADD TO CART</button>
</div>
</div>
</div>
);
}
const mapDispatchToProps = dispatch => {
return{
addItem: (item) => dispatch(addItem(item))
}
}
export default connect(null, mapDispatchToProps)(FishPage)
Okies, So, I am working on a simple recipe collection App, where I have cuisineReducer.js and RecipeReducer.js.
and on my admin Dashboard, an admin user is allowed to Create, Delete and Edit any Cuisine groups and also could Create, Delete and Edit Recipes for any Cuisine Group.
when user clicks on any cuisine group, it renders all the Recipes in Recipe Panel using Cuisine Id. user can also delete by pressing "x" on Recipe or on Cuisine group.
The conflict I need to resolve is when a recipe is deleted,it should be deleted from the ui too without the need of refresh. I dont know how to achieve that. Here is my code.
CuisineReducer.js
import { GET_CUISINES, GET_CUISINE_BY_ID, GET_CUISINE_BY_CATEGORY} from "../actions/types.js";
const initialState = {
cuisines: [],
cuisine:{}
};
export default function (state = initialState, action) {
switch(action.type) {
case GET_CUISINES:
return {
...state,
cuisines:action.payload
};
case GET_CUISINE_BY_CATEGORY:
return {
...state,
cuisines:action.payload
};
case GET_CUISINE_BY_ID:
return {
...state,
cuisine:action.payload
};
default:
return state;
}
CuisineActions.js
import { GET_CUISINES, GET_CUISINE_BY_ID} from "./types.js";
import axios from 'axios';
export const getCuisines = () =>async dispatch => { ... }
export const getCuisineByCategory = (id) =>async dispatch => {
const res = await axios.get(`/api/cuisine/${id})
dispatch({
type:GET_CUISINES_BY_CATEGORY,
payload: res.data
});
export const getCuisineById = (id) =>async dispatch => {
const res = await axios.get(`/api/cuisine/${id})
dispatch({
type:GET_CUISINE_BY_ID,
payload: res.data
});
}
recipeReducer.js
import { GET_RECIPES, GET_RECIPE_BY_ID, DELETE_RECIPE} from "../actions/types.js";
const initialState = {
recipes: [],
recipe:{}
};
export default function (state = initialState, action) {
switch(action.type) {
case GET_RECIPES:
return {
...state,
recipes:action.payload
};
case GET_RECIPE_BY_ID:
return {
...state,
recipe:action.payload
};
case DELETE_RECIPE:
return {
...state,
recipes:state.recipes.filter(asset => asset.id != action.payload)
};
default:
return state;
}
RecipeActions.js
import { DELETE_RECIPE} from "./types.js";
import axios from 'axios';
export const getRecipes = () =>async dispatch => { ... }
export const deleteRecipe = (id) =>async dispatch => {
await axios.delete(`/api/recipe/${id})
dispatch({
type:GET_RECIPE_BY_ID,
payload: id
});
}
Admin.js
import React, {Component} from react;
import {connect} from 'react-redux';
import { getCuisineById, getCuisinesByCategory} from '../../actions/cuisineAction.js';
import AdminCuisineList from '../AdminCuisineList.js;
import AdminRecipeList from '../AdminRecipeList.js";
Class Admin extends Component {
componentWillUnmount = () => {
this.props.clearCuisine();
}
revealList = category => {
this.props.getCuisinesByCategory(caegory);
}
revealRecipeList = id => {
this.props.getCuisineById(id);
}
render () {
const {cuisines} = this.props;
return(
<div>
<div>
<ul>
<li onClick={() => revealList('meal')}> Meal </li>
<li onClick={() => revealList('meal')}> Deserts </li>
<li onClick={() => revealList('meal')}> Drinks </li>
</ul>
</div>
{ cuisines &&
cuisines.map(cuisine => (
<AdminCuisineList label={cuisine.label} recipeHandler={() => this.revealRecipeList(cuisine.id)}} />
))}
{ cuisine && cuisine.recipes
cuisine.recipes.map(recipe => (
<AdminRecipeList label=recipe.label} cuisineId={recipe.cuisine[0] />
))}
);
}
}
Here is my json data for the calls I am using:
getCuisinesByCategory() GET Call
Output:
[
"label": "Indian",
"category": "Meal",
"recipes": [
{ id: "123", "label": "Chicken Biryani"},
{ id: "124", "label": "Chicken Korma"},
{ id: "125", "label: "Nihari"},
{ id: "1244", "label": "Pulao"},
{ id: "12321", "label": Pakore"},
{ id: "1232", "label": "Bun Kubab"}
]
]
It looks like you handle deleting recipes in your reducer - you are using the wrong action for when you delete your recipe. You need to use your DELETE_RECIPE action type. You are using GET_RECIPE_BY_ID
export const deleteRecipe = (id) =>async dispatch => {
await axios.delete(`/api/recipe/${id})
dispatch({
type:DELETE_RECIPE,
payload: id
});
}