Last active
July 27, 2018 16:03
-
-
Save joshjhargreaves/c9d51b8cf137b351975cf494503287dc to your computer and use it in GitHub Desktop.
Use lazy requires for screens for React Navigation
This file contains hidden or 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
//Navigator | |
const SettingsScreen = createLazyComponent( | |
() => require('../containers/component').default | |
); | |
// ... | |
const MainStackNavigator = StackNavigator( | |
{ | |
SettingsScreen: { | |
screen: SettingsScreen, | |
//LazyComponent.js | |
export default function createLazyComponent<Props>( | |
getClass: () => React.ComponentType<Props> | |
) { | |
return class extends React.PureComponent<Props> { | |
lazyComponentClass: ?React.ComponentType<Props> = getClass(); | |
render() { | |
const LazyComponent = this.lazyComponentClass; | |
if (LazyComponent == null) { | |
return null; | |
} | |
return ( | |
<LazyComponent {...this.props} /> | |
); | |
} | |
}; | |
} |
I think actually unless you need to do something specific with the children, children can be passed implicitly with the prop spread. So no issues with Flow typing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can't u use React.Node for children type?