4

I'm trying to implement the accepted answer given here

Including SVG in a Lightning Component

which uses afterRender to change the component's DOM.

Except for me, I cannot get afterRender to get called.

My code in the componentRenderer.js file is

({
afterRender: function(component, helper) {
     alert('d');
       debugger;
}
 })

but nothing happens.

I changed the function name to render, eg.

render: function(component, helper) {

and that IS called.

So what could I possibly be doing wrong? There's nothing in the JS console.

Thanks

UPDATE: it is called if I remove the afterRender that I have in the containing .app. Smells like a bug in SF. Fortunately for me I can live without the afterRender in the .app

5

You need to call the this.superAfterRender(); in your afterRender call.

0
6

In case this helps anyone else:

afterRender has to go in the Renderer of your lightning component, not the Controller or Helper.

1
  • 1
    Very well spotted. A renderer file is part of the component bundle and is auto-wired if you follow the naming convention, <componentName>Renderer.js. For example, the renderer for sample.cmp would be in sampleRenderer.js
    – oabarca
    Jan 7 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.