Closed gunnartorfis closed 2 years ago
Hi @gunnartorfis,
to my understanding, your code isn't going to work as a test for react-freeze
. But why?
react-freeze
stops React rerenders. It won't stop a function that is still running.
On the component mount, your log-counter-loop runs a function that schedules 100 promises to the Callback Queue with a timeout of 1 s. Each second event loop takes and runs one scheduled promise. It is running with and without freezing because it's not connected to the fact of whether a component is frozen or not. It's simply handled by a separate mechanism. If there would be some state change or something that causes rerender then freeze would handle that.
source: Understanding Event Loop, Call Stack, Event & Job Queue in Javascript
To test freezing we use this example in react-native-screens
.
Cheers
Wow! Thank you so much for taking the time to give me such a thorough reply. I should have figured that out myself. Thanks again.
I wanted to try out react-freeze so I decided to set up a test to see the before & after. We have a React Native application with the following navigation structure:
In our "Home" screen, I wrote this (maybe overly complex) log-counter-loop, to see if it'd run before and after react-freeze. Unfortunately it's running both with and without the library.
Top of my index.js:
To make sure index.js is the first thing that's ran by the iOS part:
Here's a screen record for showcasing:
https://user-images.githubusercontent.com/5333875/141653983-c11b51a6-eac7-4421-8573-621eaec79f54.mov