Skip to content
This repository was archived by the owner on Nov 24, 2019. It is now read-only.
This repository was archived by the owner on Nov 24, 2019. It is now read-only.

Updating subproperties with redux-query mutations #8

Description

@RcKeller

Take this code block for instance, where we are contact types for a proposal in the store as state.db.proposal

let { form, api, contact, id, indexInStore } = this.props
    form.validateFields((err, values) => {
      if (!err && values) {
        const newContact = Object.assign({}, contact, values)
        const update = ({ proposal: (prev, next) => {
          let newData = Object.assign({}, prev)
          newData.contacts[indexInStore] = newContact
          return newData
        }})
        api.patch('contact', newContact, { id, update })
        .then(message.success(`Updated ${contact.role} contact!`))
        .catch(err => {
          message.warning(`Failed to update contact - Unexpected client error`)
          console.warn(err)
        })
      }
    })

If I select next and try and work with it programmatically, redux-query will throw undefined as that promise hasn't resolved. Thus my workaround is to create a new object without mutations to prevent side affects, then return the object. This works, but has the side affect of not triggering rerenders on components dependent on this. So, in this instance, if I update the contact and return to view the proposal summary tab, the contact is the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions