4 ms·
Ugh no. Please don't use mixins or inheritance. Composition is the way to go. https://en.wikipedia.org/wiki/Composition_over_inheritance https://en.wikipedia.o
by wereHamster 11y ago
Ugh no. Please don't use mixins or inheritance. Composition is the way to go.
https://en.wikipedia.org/wiki/Composition_over_inheritance https://en.wikipedia.org/wiki/Composition_over_inheritance
- Kiro 11y agoDo you have any example React code using composition?
- wereHamster 11y agoSame 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>
- Bahamut 11y agoTo 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.