This repository has been archived by the owner on Oct 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move homepage rendering logic to routes so its ssr-able
- Loading branch information
Showing
3 changed files
with
40 additions
and
29 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// @flow | ||
// Fallback to the <Homepage /> component if there's no current user | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import Homepage from './'; | ||
|
||
// This is the component that determines at render time what to do | ||
const HomepageFallbackComp = props => { | ||
const { Component, currentUser, ...rest } = props; | ||
if (!currentUser || !Component) return <Homepage {...rest} />; | ||
return <Component {...rest} />; | ||
}; | ||
|
||
// Connect that component to the Redux state | ||
const ConnectedFallbackComp = connect(state => ({ | ||
currentUser: state.users.currentUser, | ||
}))(HomepageFallbackComp); | ||
|
||
const homepageFallback = Component => { | ||
return props => <ConnectedFallbackComp {...props} Component={Component} />; | ||
}; | ||
|
||
export default homepageFallback; |