Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform redirect also in Redirect's componentDidUpdate #5321

Closed
jfschwarz opened this issue Jul 7, 2017 · 1 comment
Closed

Perform redirect also in Redirect's componentDidUpdate #5321

jfschwarz opened this issue Jul 7, 2017 · 1 comment

Comments

@jfschwarz
Copy link

jfschwarz commented Jul 7, 2017

I would like to be able to redirect dynamically based on state. However, the Redirect component only performs the redirect in componentDidMount and not from within componentDidUpdate. This restriction seems rather artificial and to me feels counterintuitive.

My use case is as follows: An infinite scrolling list that updates the currently active page index in the location state. Some stripped-down example code:

const InfiniteList = ({ match, startIndex, rows, setStartIndex }) =>
  <div>
    <InfiniteScroll rows={rows} loadMoreRows={setStartIndex} />
    <Redirect key={index} to={`${match.url}/${startIndex}`} />
  </div>

export default compose(
  withState(
    'startIndex',
    'setStartIndex',
    ({ match }) => match.params.index || 0
  )
)(InfiniteList)

Note the key={index} prop on the Redirect element. This is my workaround for triggering componentDidMount again after every page switch. I would prefer if the redirect would just work™ without this hack.

@timdorr
Copy link
Member

timdorr commented Jul 7, 2017

See #5162 and #5003

@timdorr timdorr closed this as completed Jul 7, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants