forked from danskernesdigitalebibliotek/dpl-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ADR for react-use/useDeepComparison
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Architecture Decision Record: React Use | ||
|
||
## Context | ||
|
||
The decision of obtaining `react-use` as a part of the project originated | ||
from the problem that arose from [having an useEffect hook with | ||
an object as a dependency](https://github.com/danskernesdigitalebibliotek/dpl-react/pull/219). | ||
|
||
`useEffect` does not support comparison of objects or arrays and we needed | ||
a method for comparing such natives. | ||
|
||
## Decision | ||
|
||
We decided to go for the react-use package | ||
[react-use](https://github.com/streamich/react-use). | ||
The reason is threefold: | ||
|
||
* It could solve the problem with deep comparison of dependencies by using | ||
`useDeepCompareEffect` | ||
* It offered an alternative to the | ||
[react-hook-inview](https://www.npmjs.com/package/react-hook-inview) viewport handling. | ||
So we did not need to use two packages. | ||
* It has a range of other utility hooks that we can make use of in the future. | ||
|
||
## Alternatives considered | ||
|
||
We could have used our own implementation of the problem. | ||
But since it is a common problem we might as well use a community backed solution. | ||
And `react-use` gives us a wealth of other tools. | ||
|
||
## Consequences | ||
|
||
We can now use `useDeepCompareEffect` instead of `useEffect` | ||
in cases where we have arrays or objects amomg the dependencies. | ||
And we can make use of all the other utility hooks that the package provides. |