Skip to content

Instantly share code, notes, and snippets.

@iamdey
Last active April 28, 2021 17:20
Show Gist options
  • Save iamdey/2793acee67fa0372e4aa0c5d39ce5d73 to your computer and use it in GitHub Desktop.
Save iamdey/2793acee67fa0372e4aa0c5d39ce5d73 to your computer and use it in GitHub Desktop.
The pyramid of doom of the Render Prop react pattern
import React, { Component } from 'react'
import PropTypes from 'prop-types'
// ...
class Foo extends Component {
createHandleSearchChange = (tags) => terms =>
this.setState({ foundTags: whateverFindAlgo(tags, terms)})
handleAddTag = (updateEntityTags, entity, tag) => {
updateEntityTags(entity, [...entity.tags, tag])
}
render() {
return (
<WithTags render={(tags, isTagsFetching) => (
<WithEntity render={(entity) => (
<WithUpdateEntityTags render={(updateEntityTags) => {
const handleAddTag = this.handleAddTag.bind(null, updateEntityTags, entity);
return (
<div className="whatever">
<SearchTagInput
onChange={this.createHandleSearchChange(tags)}
isFetching={isTagsFetching}
/>
<SearchResults
foundTags={this.state.foundTags}
onAdd={handleAddTag}
/>
</div>
)
}} />
)} />
)} />
);
}
}
@iamdey
Copy link
Author

iamdey commented Feb 5, 2018

The solution to prevent this is to use this, https://github.com/jmeas/react-composer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment