Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
How to properly dispatch an axios delete with react redux

I am trying to get the state to refresh after a delete request. The correct id is being deleted but it is not refreshing the state at all because the action payload is empty. Below is my current code.

actions\index.js

...
function deleteCustomerSucceeded(customer){
    return{
        type:"DELETE_CUSTOMER_SUCCEEDED",
        payload:{
           customer
        }
    }
}

export function deleteCustomer(id){
    return(dispatch) =>{
        api.deleteCustomer(id).then((res) => {
            dispatch(deleteCustomerSucceeded(res.data))
        })
    }
...

reducers\index.js

...
    case 'DELETE_CUSTOMER_SUCCEEDED':{
        return{
            ...state,
            customers: state.customers.filter(customer => customer.id !== action.payload)
        }
    }
...

api\index.js

export function deleteCustomer(id){
    return client.delete(`/customers/${id}`)
}

myview.js

  deleteCustomer(){
      let state = {submitted: true}
      this.props.onDeleteCustomer(this.state.customer.id)
      state = {
        ...state,
        customer: this.emptyCustomer,
        deleteCustomerDialog: false
    }
    this.setState(state)
  }

Let me know if there needs to be any further clarification or any additional code you may need to see to help answer this question.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

After Kapobajza answer I made these changes to my code to make it work.

reducers\index.js

    case 'DELETE_CUSTOMER_SUCCEEDED':{
        return{
            ...state,
            customers: state.customers.filter(customer => customer.id !== action.payload.id)
        }
         
    }

actions\index.js

function deleteCustomerSucceeded(id){
    return{
        type:"DELETE_CUSTOMER_SUCCEEDED",
        payload:{
           id
        }
    }
}

export function deleteCustomer(id){
    return(dispatch) =>{
        api.deleteCustomer(id).then((res) => {
            dispatch(deleteCustomerSucceeded(id))
        })
    }
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!