Mixins
Components are great to achieve reusability, but what if different components in different domains share the same behavior?
We do not want duplicated code in our applications, and React gives us a tool that we can use when we want to share functionalities across various components:Â mixins.
Using mixins is no longer recommended, but it is worth understanding the problems they tried to solve and see what the possible alternative solutions are.
Also, it could happen that you might have to work on a legacy project that uses an older version of React, and it makes sense to know what mixins are and how to deal with them.
First of all, mixins work only with the createClass
factory, so if you are using classes, you cannot use mixins, and that is one of the reasons why their usage is discouraged.
Suppose you are using createClass
in your application and you find yourself needing to write the same code into different components.
For example, you need to listen to the window resize event to get the...