There are a few simple rules that make mixins safer:
- Mixins should not know about each other. (No implicit dependencies).
- Mixins should be small. Introduce as few new properties as possible.
- When composing, you can and should selectively inherit only the props you need, and rename props to avoid collisions.
- Prefer modules for code reuse whenever you can (which should be most of the time).
- Prefer functional programming for domain models and state management. Avoid shared mutable state.
- Prefer higher order functions and higher order components over inheritance of any kind (including mixins).
Mixins are immune to the fragile base class problem if you avoid creating inheritance hierarchies with them, and instead rely on feature-based composition.
People get into trouble with mixins when they try to treat them like classes. Don’t do that.