3 ms·
Wow, this looks cool! How is use_state() implemented?
by citywide-fondue 4y ago
Wow, this looks cool! How is use_state() implemented?
- enricozb 4y agoSimilarly to how React does it I'd imagine. There is a static vector of `State` elements that is initially empty and is filled on the first render with each call to use_state. When calling use_state on subsequent renders, this vector is read from. This is also why, like React, use_state calls must always be in the same order across renders.