Hacker News new | ask | show | jobs
by sibeliuss 3008 days ago
const Name = (props) => <div>{props.name}</div>

const Age = (props) => <div>{props.age}</div>

const App = () => <div><Name name={'Zed'}/><Age age={20} /></div>

Is about as simple as it gets. This sort of composability can go _very_ far without needing any of the other API methods.

1 comments

I looked up HOCs not long after writing the comment, and I agree -- this is much better than the mixin approach that used to be the way (though if I remember correctly, mixins were considered 'temporary' at the time).

This isn't a benefit of react though -- this is just react incorporating a well known functional paradigm, which I don't mind.

IMO If react was simple, this would have been the way to do it from the start -- no mixins detour. This answer would have fallen out (as it now has), if they simply didn't offer a way to inherit functionality, in that manner. If a component is truly just a function from state to output, the obvious way to combine them IS higher order functions.