Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dequal instead of JSON.stringify for useDeepCallback. #276

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"url": "https://github.com/alex-cory/use-http.git"
},
"dependencies": {
"dequal": "^1.0.0",
"urs": "^0.0.7",
"use-ssr": "^1.0.22",
"utility-types": "^3.10.0"
Expand Down Expand Up @@ -56,7 +57,7 @@
"scripts": {
"prepublishOnly": "yarn build:production && yarn build:production:esm # runs before publish",
"build": "rm -rf dist/cjs && tsc --module CommonJS --outDir dist/cjs",
"build:esm": "rm -rf dist/esm && tsc",
"build:esm": "rm -rf dist/esm && tsc",
"build:production": "yarn build -p tsconfig.production.json",
"build:production:esm": "yarn build:esm -p tsconfig.production.json",
"build:watch": "rm -rf dist && tsc -w --module CommonJS",
Expand Down Expand Up @@ -122,4 +123,4 @@
"useGraphQL",
"use-graphql"
]
}
}
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useMemo, useEffect, MutableRefObject, useRef, useCallback, DependencyLi
import useSSR from 'use-ssr'
import { RequestInitJSON, Options, Res, HTTPMethod, ResponseType } from './types'
import { FunctionKeys, NonFunctionKeys } from 'utility-types'
import deepEqual from 'dequal'

/**
* Used for error checking. If the condition is false, throw an error
Expand Down Expand Up @@ -232,7 +233,7 @@ export const serializeResponse = async (response: Response) => {

function useDeepCompareMemoize(value: DependencyList) {
const ref = useRef<DependencyList>()
if (JSON.stringify(value) !== JSON.stringify(ref.current)) ref.current = value
if (!deepEqual(value, ref.current)) ref.current = value
return ref.current as DependencyList
}

Expand Down
13 changes: 9 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,11 @@ delayed-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk=

dequal@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/dequal/-/dequal-1.0.0.tgz#41c6065e70de738541c82cdbedea5292277a017e"
integrity sha512-/Nd1EQbQbI9UbSHrMiKZjFLrXSnU328iQdZKPQf78XQI6C+gutkFUeoHpG5J08Ioa6HeRbRNFpSIclh1xyG0mw==

detect-newline@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651"
Expand Down Expand Up @@ -4561,10 +4566,10 @@ urix@^0.1.0:
resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72"
integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=

urs@^0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/urs/-/urs-0.0.4.tgz#d559d660f2a468e0bb116e0b7b505af57cb59ae4"
integrity sha512-+QflFOKa9DmjWclPB2audGCV83uWUnTXHOxLPQyu7XXcaY9yQ4+Tb3UEm8m4N7abJ0kJUCUAQBpFlq6mx80j9g==
urs@^0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/urs/-/urs-0.0.7.tgz#2dbf320a68a54bbd67ab9c5ac103b0f2227ca6be"
integrity sha512-NDwuby5BP7D60RjHlow8Gch4yfglLdCpZagGeVDZNcL+jsA2v6RcBhPTJraqq1oQ1U3LT1bQfgmwgNUUIFht+g==

use-ssr@^1.0.22:
version "1.0.22"
Expand Down