Skip to content

Instantly share code, notes, and snippets.

@evturn
Last active June 21, 2016 07:10
Show Gist options
  • Save evturn/ff0f7bae270fe955a74ead8450c978a0 to your computer and use it in GitHub Desktop.
Save evturn/ff0f7bae270fe955a74ead8450c978a0 to your computer and use it in GitHub Desktop.
Inward React Nesting
const { cloneElement } = React
const plopProps = plops => (
props => (
inward => (
plops(props)
? cloneElement(plops(props), props, (plops(props).props.children || []).concat(inward.plops(props)))
: inward.plops(props)
)
)
)
const Inward = plops => {
return {
plops,
concat: inward => Inwardprops => plopProps(plops)(props)(inward))
}
}
const plopReducer = (acc, x) => acc.concat(x)
const Name = ({ name }) => <span>{name} really enjoys </span>
const Activity = ({ activity }) => <em>{activity}.</em>
const App = [Name, Activity]
.map(Inward)
.reduce(plopReducer, Inward(_ => null))
.plops
ReactDOM.render(
<App
name="Fred Estaircase"
activity="eating dolphins"
/>,
document.getElementById('container')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment