Effect memoization and immutable data structures
See original GitHub issueCurrent design of useEffect
requires dependencies to be either primitive values or references to the same object, because shallow equality check relies on Object.is
which is an identity check for objects.
The above means that there’s no way to perform structural comparison, which is needed for immutable data structures when identity check fails.
To maintain backwards compatibility a comparator function could be provided as the third argument to useEffect
:
useEffect(fn, deps, depsComparator);
The goal here is to preserve an ease of use of the API with immutable data structures in order to provide an idiomatic usage of useEffect
in ClojureScript and other environments that rely on immutability e.g. Immutable.js
Issue Analytics
- State:
- Created 5 years ago
- Reactions:28
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Memoization: a good use case for a mutable data structure?
The Scala philosophy seems to be to use an immutable data structure unless you have a very good reason not to.
Read more >Immutability in Javascript, React, and Immutable.js - Medium
The ability to freely mutate your original data structure and thereby propagating changes to all the other objects that reference to it can...
Read more >React.js Conf 2015 - Immutable Data and React - YouTube
Lee Byron, FacebookImmutable data unlocks powerful memoization techniques and prohibits accidental coupling via shared mutable state.
Read more >Functional Programming With Java: Immutability
The fundamental idea behind immutability is simple: If we want to change a data-structure, we need to create a new copy of it...
Read more >How do immutable data structures and statelessness reduce ...
I'm not sure what you mean by “statelessness”, but immutable data structures certainly eliminate mutation side effects; that's the guarantee. · Ordinary classes ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think typed-in literals are too small to worry about. From #14476 -
Comparing small structures like
{:some "map" :that "I typed in"}
is always going to be fast.Which means that if I want to skip based on a custom equality check (by custom I mean not the one provided by React), I can just do it before calling
setState
since I have access to both the old and new state.