Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

firing actions in response to route transitions in react-router #227

Closed
@deowk

Description

@deowk

Hi Guys,

I am using react-router and redux in my latest app and I'm facing a couple of issues relating to state changes required based on the current url params and queries.

Basically I have a component that needs to update it's state every time the url changes. State is being passed in through props by redux with the decorator like so

 @connect(state => ({   campaigngroups: state.jobresults.campaigngroups,   error: state.jobresults.error,   loading: state.jobresults.loading }))

At the moment I am using thecomponentWillReceiveProps lifecycle method to respond to the url changes coming from react-router since react-router will pass new props to the handler when the url changes inthis.props.params andthis.props.query - the main issue with this approach is that I am firing an action in this method to update the state - which then goes and passes new props the component which will trigger the same lifecycle method again - so basically creating an endless loop, currently I am setting a state variable to stop this from happening.

  componentWillReceiveProps(nextProps) {    if (this.state.shouldupdate) {      let { slug } = nextProps.params;      let { citizenships, discipline, workright, location } = nextProps.query;      const params = { slug, discipline, workright, location };      let filters = this._getFilters(params);      // set the state accroding to the filters in the url      this._setState(params);      // trigger the action to refill the stores      this.actions.loadCampaignGroups(filters);    }  }

Is there a standard approach to trigger actions base on route transitions OR can I have the state of the store directly connected to the state of the component instead of passing it in through props? I have tried to usewillTransitionTo static method but I don't have access to the this.props.dispatch there.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp