Skip to content

Latest commit

 

History

History
57 lines (43 loc) · 1.03 KB

redux.md

File metadata and controls

57 lines (43 loc) · 1.03 KB

<   Redux Conventions

 


 

Async Error Handling

import { InsufficientFundsError } from ‘edge-core-js’
WALLET_API.someCall(edgeWallet, someInputs).then(handleSuccess, handleError)
const handleSuccess = (someData) => {...do stuff with data}
const handleError = (error: Error) => {
  if (error instanceof InsufficientFundsError) {
    return dispatch(displayInsufficientFundsAlert())
  }
  dispatch(unknownError(error)) // Handles all other error types
}

Back to the top

 

Connectors

  • Do not create new objects in connectors
const defaults = {
  d: 123,
  e: 456
}
const mapStateToProps = (state: State) => {
  return {
    a: {
      ...defaults,
      ...state.a
    },
    b: state.b,
    c: state.c
  }
}
export const connectedMyComponent = connect(mapStateToProps, mapDispatchToProps)(MyComponent)

Back to the top