This updates the cache algorithm to use WeakMap that stores the state updater instead of an hash generated by the callback and the additional parameters. Creating an hash with a string representation of the additional parameters invalidated the cache and created a new handler even thought it was not necessary.
This change adds a limitation since if we reuse the state updater with different parameters it will attach the ones passed on the last call of update()/handle(). This is a tradeoff in order to keep the referential identity of the callback handlers across multiple renders.
This updates the cache algorithm to use
WeakMap
that stores the state updater instead of an hash generated by the callback and the additional parameters. Creating an hash with a string representation of the additional parameters invalidated the cache and created a new handler even thought it was not necessary.This change adds a limitation since if we reuse the state updater with different parameters it will attach the ones passed on the last call of
update()/handle()
. This is a tradeoff in order to keep the referential identity of the callback handlers across multiple renders.