-
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.
perf(*): add warning when passing empty dependecies or primitive depe…
…ndecies
- Loading branch information
lintuming
committed
Sep 9, 2019
1 parent
8b0d00f
commit da6f6aa
Showing
11 changed files
with
175 additions
and
17 deletions.
There are no files selected for viewing
Empty file.
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 |
---|---|---|
|
@@ -49,6 +49,6 @@ const useSomething=()=>{ | |
} | ||
``` | ||
|
||
## LICENSE | ||
## License | ||
|
||
- [MIT](./LICENSE) |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module.exports = { | ||
clearMocks: true | ||
clearMocks: true, | ||
testMatch: ['<rootDir>/src/**/__tests__/*.test.{js,jsx,ts,tsx}'], | ||
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts', '!src/__tests__/*'], | ||
}; |
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
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
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
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
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
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,11 @@ | ||
export function getEmptyDepsMsg(hookName) { | ||
const originName = `use${hookName.slice(10)}`; | ||
|
||
return `\`${hookName}\` should not be used with no dependencies. Use React.${originName} instead.`; | ||
} | ||
|
||
export function getPrimitiveDepsMsg(hookName) { | ||
const originName = `use${hookName.slice(10)}`; | ||
|
||
return `\`${hookName}\` should not be used with dependencies that are all primitive values. Use React.${originName} instead.`; | ||
} |
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
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { useEffect, useRef, DependencyList } from 'react'; | ||
import { useRef, DependencyList } from 'react'; | ||
import shallowEquals from './shallowEqual'; | ||
|
||
export default function useShallowDeps(lastestDeps: DependencyList) { | ||
const depsRef = useRef(lastestDeps); | ||
const deps = shallowEquals(lastestDeps, depsRef.current) ? depsRef.current : lastestDeps; | ||
useEffect(() => { | ||
depsRef.current = deps; | ||
}, [deps]); | ||
return deps; | ||
|
||
if (!shallowEquals(depsRef.current, lastestDeps)) { | ||
depsRef.current = lastestDeps; | ||
} | ||
|
||
return depsRef.current; | ||
} |