Hacker News new | past | comments | ask | show | jobs | submit login

Ugh no. Please don't use mixins or inheritance. Composition is the way to go.

https://en.wikipedia.org/wiki/Composition_over_inheritance




Do you have any example React code using composition?


Same way you compose functions or HTML elements.

Functions:

    add(1,multiply(2,3))
HTML:

    <div>foo <span>bar</span> </div>
React:

    <Container> <Header>foo</Header> <p>content</p> </Container>


To be pedantic, that is not quite composition - I've made this exact mistake before too. Composition is where you have a function f o g (o being the traditional mathematical notation for composition), where (f o g)(a) = b satisfies g(f(a)) = b.

Composition is a useful tool, and so is writing functions like this, but they are two different ideas.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: