Tram-One/tram-one

implement useMemo hook

Closed this issue · 1 comments

Summary

React has a useMemo hook used for persisting values that should not be re-evaluated if a set of dependencies has not been updated.

It's a similar interface to useEffect, but returns a value, and has no cleanup step. The useMemo hook also runs in the component evaluation, not after the component has rendered (so it will not be queued like effects are).

Potential Implementation

This feels like a simple enough hook to implement. If using useState, it's potentially possible to make this hook by storing both the dependencies and the last evaluated value, and checking if those dependencies have changed. If they haven't changed, you can return the value that is already saved, otherwise evaluate the function.

given the observable updates, this hook should no longer be required