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.

[BUG] onInit() is executed AFTER the widget renders

See original GitHub issue

self.onInit() is executed only after the widget renders, which is a problem for initialization of the initial values. Is there any way around it?

An analog of the method which I am looking for is componentWillMount in React. This method is only called before the initial render.

Code to replicate the issue:

HTML:

<script>
    console.log($customValue)
</script>

JS:

 self.onInit = function() {
        self.ctx.$scope.data = self.ctx.defaultSubscription.data
        $customValue = self.ctx.defaultSubscription.data[0]

        console.log($customValue)
    }

Expected result:

$customValue is printed two times in the console

Actual result:

  • first printed line: ReferenceError: $customValue is not defined[Learn More]
  • second printed line: actual value of $customValue

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
nsantos111commented, Jun 19, 2019

Hi @alexsmartens,

After reading some articles about jQuery I put my hands on the task of moving from my very complex static html to the jQuery built layout. During the process of wall breaking with my head, I found an error on my initial JS code. After fixing it, the errors on the functions called from the html were fixed - the issue was not related with onInit() not being called before the html rendering after all!

Thanks for your support and for pointing the jQuery option – is something that I must get into but definitely with a more simple html layout.

1reaction
nsantos111commented, Jun 14, 2019

Yes, that’s more or less the case. I’m not looking for whether the checkboxes are selected or not, but for some properties of the array objects - and have one checkbox row for each object. The array is filled in at onInit() beginning. The issue occurs when the array is not filled before the rendering of the html which only happens sometimes.

I understood your suggestion (of building the elements on onInit instead of in the html part) and if there’s no other solution I’ll give it a try as soon as I finish other widget I’m implementing - Never used jQuery before…

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flutter: Run method on Widget build complete - Stack Overflow
which executes a function only one time after the layout is completed. ... widgets are rendered here await yourFunc(); runApp( MyApp() ); }....
Read more >
Screen and Block Lifecycle Events - OutSystems documentation
The On Render event handler runs after each time the Screen or Block is rendered, i.e. whenever the Screen or Block is opened...
Read more >
After render method in a Widget - Esri Community
Hello Esri community, Is there a method or event in a widget that will be executed after rendering elements into the dom?
Read more >
Widget Client Script function run after HTML Form - ServiceNow
Solved: Hey, I have a Widget with a HTML Table with Input-Fields. ... should be fully rendered before your client script would execute....
Read more >
reactter 2.3.0-dev.3 | Flutter Package
ReactterBuilder create a scope where isolates the widget tree which will be re-rendering when all or some of the specified ReactterHook dependencies on ......
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