3 ms·
Agreed it’s implicit. I think it works by keeping track of start and end of Component rendering and counting the function calls to useState in between. You can
by ajcodez 8y ago
Agreed it’s implicit. I think it works by keeping track of start and end of Component rendering and counting the function calls to useState in between. You can imagine the following sequence of events.
- Enter Component A
- Use State A0 (does not exist, set default value)
- Exit Component A
Where calling setA0 sets the value at index 0 for Component instance A and queues render again.
- Enter Component A
- Use State A0 (has existing value)
- Exit Component A