nanojsx / nano

🎯 SSR first, lightweight 1kB JSX library.
http://nanojsx.io
MIT License
1.46k stars 38 forks source link

added didUpdate() #89

Closed jrson83 closed 2 years ago

jrson83 commented 2 years ago

Reference Issues/PRs

None

What does this implement/fix?

To create new/more opportunities for developers, the following methods have been added:

Todo

The Nano JSX Component Lifecycle

Mounting

These methods are called in the following order when a class component is created and rendered:

Updating

When calling this.update() on a class component, these methods are called in the following order:

Unmounting

This method is called when a class component gets removed/unmounted:


Thanks to Robert Boes!

jrson83 commented 2 years ago

What is the purpose of willUnmount()?

This can be useful for clean up. It is invoked immediately before a component is unmounted. You can cancel network requests and invalidate timers, remove event listeners or subscriptions. It allows for transitions, so you can add classes at that point, add a listener for when the CSS event ends. You can possibly make the willUnmount() async, so it will wait with unmounting when the CSS animation is finished and you return from the function.