Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Last active September 4, 2019 09:26
Show Gist options
  • Save JakeGinnivan/81392472cf0d57bb30a5f24a70112f0f to your computer and use it in GitHub Desktop.
Save JakeGinnivan/81392472cf0d57bb30a5f24a70112f0f to your computer and use it in GitHub Desktop.

Revisions

  1. JakeGinnivan revised this gist Sep 4, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion react-ssr-component-data-load.jsx
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    jsx
    class SomethingComponent extends React.Component {
    componentWillMount() {
    // If we don't have an article, load it
  2. JakeGinnivan renamed this gist Sep 4, 2019. 1 changed file with 0 additions and 0 deletions.
  3. JakeGinnivan created this gist Sep 4, 2019.
    22 changes: 22 additions & 0 deletions react-ssr-component-data-load
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    jsx
    class SomethingComponent extends React.Component {
    componentWillMount() {
    // If we don't have an article, load it
    if (!this.props.article) {
    this.props.dispatch(loadArticle(this.props.id))
    }
    }

    render() {
    if (this.props.loading) {
    return <div>Loading...</div>
    }

    return <Article article={this.props.article} />
    }
    }

    // For this example, we only have a single state tree
    // so no need to use mapStateToProps to narrow the data
    // we are connecting to
    export default connect(state => state)(SomethingComponent)