# Can we create Mixins in Stimulus?

**URL:** https://discuss.hotwired.dev/t/can-we-create-mixins-in-stimulus/450
**Category:** General
**Created:** [September 22, 2018, 8:37pm UTC](https://discuss.hotwired.dev/t/can-we-create-mixins-in-stimulus/450 "2018-09-22T20:37:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![GesJeremie](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/gesjeremie/32/339_2.png) [@GesJeremie](https://discuss.hotwired.dev/u/GesJeremie)
#### Post date: [September 22, 2018, 8:37pm UTC](https://discuss.hotwired.dev/t/can-we-create-mixins-in-stimulus/450/1 "2018-09-22T20:37:49Z")

</div>

Hey 🙂

I’m using stimulus on a side project and I wanted to create a Mixin (aka methods you can inject in a controller) to avoid duplication of my code in different controllers.

What’s the “right” way in stimulus to do that.

Basically I’m looking for that concept: [https://vuejs.org/v2/guide/mixins.html](https://vuejs.org/v2/guide/mixins.html)

---

<div class="post-metadata">

### Author: ![sudara](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/sudara/32/67_2.png) [@sudara](https://discuss.hotwired.dev/u/sudara)
#### Post date: [September 23, 2018, 12:51am UTC](https://discuss.hotwired.dev/t/can-we-create-mixins-in-stimulus/450/2 "2018-09-23T00:51:53Z")

</div>

You can extend controllers [as described here](https://discuss.hotwired.dev/t/what-s-planned-for-stimulus-1-1/144/10?u=sudara) to inherit the targets/methods. That’s been pretty useful for me.

You can also have multiple stimulus controllers per DOM element, essentially letting you mix and match groups of behaviors on the fly. I find it nicest to keep stimulus methods concerned with just responding to events on targets and light data/dom manipulation and tuck more complex logic away in other modules.

---

<div class="post-metadata">

### Author: ![woto](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/woto/32/759_2.png) [@woto](https://discuss.hotwired.dev/u/woto)
#### Post date: [December 3, 2021, 4:28pm UTC](https://discuss.hotwired.dev/t/can-we-create-mixins-in-stimulus/450/3 "2021-12-03T16:28:45Z")

</div>

I’ve searched this question too and found this super useful [Mixins - Better StimulusJS](https://www.betterstimulus.com/architecture/mixins.html)
