lifecycle events as attributes?
See original GitHub issueI’ve been thinking about this a bit lately. The only reason you would ever need a class-based component (with a redux-style architecture) is if you need the lifecycle events.
The lifecycle events seem awfully similar to the onClick
, onMouseDown
event handlers, so I’m wondering if it would be possible to include those events like onMount
as attributes on the vnodes?
Maybe they would only work on the component level, but with mutation observers, I think they could work on any element. Here’s some repos I’ve used in the past for the mutation events:
Issue Analytics
- State:
- Created 7 years ago
- Comments:15 (8 by maintainers)
Top Results From Across the Web
Lifecycle event properties
Lifecycle event properties control the behavior of lifecycle events. You can set the duration of the activity set closure time in hours.
Read more >How do JavaScript Page Lifecycle Events work? - Tilo Mitra
The lifecycle of an HTML page has three important events: ... Attributes async and defer work only for external scripts.
Read more >How To Create Lifecycle Events
Lifecycle events can be configured to run based on events that occur in IdentityIQ. For example, when a manager change is detected for...
Read more >Lifecycle hooks - Angular
A component instance has a lifecycle that starts when Angular instantiates the component class and renders the component view along with its child...
Read more >Screen and Block Lifecycle Events - OutSystems documentation
Screens and Blocks follow a lifecycle composed by a set of stages. Learn what those stages are and you what can do at...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
for what it’s worth, this is what I settled on for functional components:
The problem I ran into with the previous approaches in the functional case was that
inst
would get reset and onMount would get called every re-render. By checking the actual element, it will only get called when the element is added and removed.UPDATE: You’ll also need to add a check for the server. Here’s the complete example: https://github.com/matthewmueller/vcom/blob/2cbffdc7fe4ac2e10c9527c3cb9a0b4541333c7e/index.js#L179-L211
@matthewmueller also: I wonder if it would be better to just steal the corresponding lifecycle method names from the Web Components spec?
Then we could really start to look into making Preact a mechanism for building and shipping Web Components…