Last active
September 20, 2016 14:32
-
-
Save ryanflorence/fa596c3a0f481088e087e72998d894cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Match, Redirect } from 'react-router' | |
// With the way we use Redirect in this demo, the word "AddressBar" probably | |
// makes more sense! | |
const AddressBar = ({ url }) => ( | |
<Redirect to={url}/> | |
) | |
class InfniteArticleHomePage extends React.Component { | |
state = { | |
articles: [ this.props.initialArticle ] | |
} | |
getNextArticle = () => { | |
fetchArticle((article) => { | |
this.setState({ | |
articles: this.state.articles.concat([ article ]) | |
}) | |
}) | |
} | |
render() { | |
const { articles } = this.state | |
return ( | |
<ScrollBottomNotifier onScrollBottom={this.getNextArticle}> | |
<div> | |
{articles.map((article) => ( | |
// all articles will match, so they will all render at any | |
// article's URL | |
<Match pattern="/article/:id" component={Article}/> | |
))} | |
{articles.length > 1 && ( | |
// set the address bar to the last article we've loaded | |
// if you're still bothered that it's a redirect, consider | |
// this an input ... that's not weird anymore. | |
<AddressBar url={`/article/${articles[articles.length - 1].id}}/> | |
)} | |
</div> | |
</ScrollBottomNotifier> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using
Redirect
wouldnt that mean each call to it would replace the last url — which would mean you cant go back in history. How would I approach it if want to maintain the previous urls. On a side note, I love what you guys did withreact-router
.