Skip to content

Pass prevState as argument to onLeave #3612

@albertogasparin

Description

@albertogasparin

This is a little enhancement I'm asking for. Currently, both onEnter and onChange have router state passed as an argument. That allows us doing stuff with router location and parameters. However, it is not the case for onLeave. Is there any particular reason?

Use case example: I'd like to handle socket.io room joining/leaving on the router.

<Route path="/" component={App}>
  <Route 
    path="/chat/:id" 
    component={Chat} 
    onEnter={(nextState) => { 
      joinChat(nextState.params.id); 
    }}
    onChange={(prevState, nextState) => { 
      leaveChat(prevState.params.id); 
      joinChat(nextState.params.id); 
    }}
    onLeave={(prevState) => { 
      leaveChat(prevState.params.id); 
    }}
  />
</Route>

I know this could be handled by the component itself, but I'm questioning why not passing the previous state to the onLeave callback, as it might be helpful in some situations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestUsed to close PRs that haven't gone through/been accepted the Proposal process yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions