2
lopu
17h

How bad would you say it is to have plain javascript in the root of a functional React component lifecyle loop scope.

I sometimes do hardwired modifcations right before the return because I know it needs to run everytime and the performance hit is minimal... Or is it ? 🤔

And sometimes it's just not worth the hassle of all the dependancy management just to save a couple of operations ..?

See pic attached .. Even looking at this picture now I realised I've accidentally added another React hook BELOW this code, luckily only 1.

I think my reasoning for this was to allow some provider functions to be passed around and used anywhere in this app which accesses the context. Is this a no-no too?

Comments
  • 0
    Why was this downvoted???
  • 2
    @TeachMeCode there is a serial downvoter on the loose. We don’t know who it is.
  • 0
    I think React doesn't promise that your component's last render won't be scheduled after teardown, I think render code can be called whenever React feels like it as long as it's done with a combination of component state that at some point in the past belonged to a component of the correct type.
  • 0
    besides that, I don't have a problem with this. It's clearly idempotent, and React really isn't so much a pure functional framework as it is a message passing one; object-orientation with flexible scheduling.
Add Comment