question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to write inheritance with stimulus controller ?

See original GitHub issue
// javascript/packs/controllers/parent_controller.js
import { Controller } from "stimulus"
export class ParentController extends Controller {
  myParentFunction(){
  }
}
// javascript/packes/controllers/child_controller.js
import { ParentController } from "parent_controller.js"
export default class extends ParentController {
  connect(){
    console.log("child controller loaded!")
  }    
}                               

I have this error:

Uncaught TypeError: Super expression must either be null or a function, not object

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
thooamscommented, Feb 6, 2018
// javascript/packs/controllers/parent_controller.js
import { Controller } from "stimulus"
export class ParentController extends Controller {
  myParentFunction(){
  }
}
// javascript/packes/controllers/child_controller.js
import  ParentController from "parent_controller.js"
export default class extends ParentController {
  connect(){
    console.log("child controller loaded!")
  }    
}                               

Resolved, just remove brackets in child controller file.

3reactions
javancommented, Jul 11, 2018

That should probably be more like:

import ParentController from "./parent_controller"
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to write inheritance with stimulus controller ? #94 - GitHub
Resolved, just remove brackets in child controller file. 8
Read more >
Mixins - Better StimulusJS
Stimulus controllers are meant to be used as mixins themselves (i.e. applying multiple controllers to one DOM element, thus mixing in behavior). Sometimes ......
Read more >
Controllers - Stimulus Reference - Hotwire
Each controller class inherits from the Controller base class exported by the @hotwired/stimulus module.
Read more >
Stimulus - Inheriting functionality - CodePen
// so we'll inherit the `connect()` & `static get targets()` functions. ... application.register("child", ChildController); !
Read more >
Developers - How to write inheritance with stimulus controller ? -
javascript/packs/controllers/parent_controller.js import { Controller } from "stimulus" export class ParentController extends Controller ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found