Solid: Question regarding afterEffects

Created on 18 Sep 2020  路  2Comments  路  Source: ryansolid/solid

I've been a ReactJS developer for a few years and have been looking for something that felt similar, but was less bloated and heavy. Solid is exactly what I was looking for and I've been really enjoying it so far.

I'm currently converting an early project from ReactJS to Solid. In one of my ReactJS components I run a function after the component mounts using the "componentDidMount" lifecycle. I was looking for something similar for Solid and came across "afterEffects" in the API.

Do these perform similar tasks in that it is effectively a callback for when the component has finished mounting?

Thanks!

question

Most helpful comment

Yes that's the intention. The biggest challenge though is that afterEffects is just something that runs synchronously after the reactive system has completed and brings no guarentees of being mounted, just that the elements are created, almost the same as calling setTimeout. That being said in 99% of cases this is the same as being mounted. The only real exception is when components are Suspended. So not taking Suspense in mind this the "hook" you are looking for. If you aren't looking at using Suspense right now, you can stop reading now.

I've been working on updating this behavior to make it more intuitive. RIght now afterEffects is not reactive in its own right which leads to a bit of boilerplate when you want these effects to update. I'm in the process of making changes here. It's unfortunate but to properly tie to together the Async system requires an update to the model. These should be the last big pre 1.0 changes. The RFC is here: https://github.com/ryansolid/solid/issues/225

To be fair this gets a bit too much into the details in some places but not others. But the intention is to provide an API where we can be confident of when effects run and removes some of the end-user complication.

All 2 comments

Yes that's the intention. The biggest challenge though is that afterEffects is just something that runs synchronously after the reactive system has completed and brings no guarentees of being mounted, just that the elements are created, almost the same as calling setTimeout. That being said in 99% of cases this is the same as being mounted. The only real exception is when components are Suspended. So not taking Suspense in mind this the "hook" you are looking for. If you aren't looking at using Suspense right now, you can stop reading now.

I've been working on updating this behavior to make it more intuitive. RIght now afterEffects is not reactive in its own right which leads to a bit of boilerplate when you want these effects to update. I'm in the process of making changes here. It's unfortunate but to properly tie to together the Async system requires an update to the model. These should be the last big pre 1.0 changes. The RFC is here: https://github.com/ryansolid/solid/issues/225

To be fair this gets a bit too much into the details in some places but not others. But the intention is to provide an API where we can be confident of when effects run and removes some of the end-user complication.

Excellent, appreciate the quick and informational answer. Keep up the great work! I intend to use Solid for a long time to come.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jcuenod picture jcuenod  路  7Comments

aguilera51284 picture aguilera51284  路  7Comments

samadadi picture samadadi  路  7Comments

ryansolid picture ryansolid  路  8Comments

ajihyf picture ajihyf  路  6Comments