Skip to content

Instantly share code, notes, and snippets.

@reggie3
Created October 19, 2018 19:23
Show Gist options
  • Save reggie3/8c7045da5343cb0889cddcc061fd9646 to your computer and use it in GitHub Desktop.
Save reggie3/8c7045da5343cb0889cddcc061fd9646 to your computer and use it in GitHub Desktop.
passing props to shared render prop
<CreateNewLocationMediaItemRP
// pass redux dispatch and actions to the RP to receive as props
dispatch={this.props.dispatch}
actions={actions}
// Use callbacks so that platform specific methods can call a function
// in the RP.
// The callback is a function passed from the RP to this component.
// This enables the platform specific function this.takeNewPictureOrVideo can
// call a function in the RP.
onTakeNewPicture={(callback) => {
this.takeNewPictureOrVideo('Images', callback);
}}
// Hoist the renderProps to the top level of the function so that methods
// can access it.
// Use a conditional to ensure it's only done once and when the component
// is mounted.
render={(renderProps) => {
if (!this.renderProps && this.state.isMounted) {
this.renderProps = renderProps;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment