-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(add) : Add support for eslint (airbnb style guide).
- Loading branch information
1 parent
b4d415b
commit 917ece0
Showing
3 changed files
with
48 additions
and
23 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,23 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es6": true | ||
}, | ||
"extends": ["plugin:react/recommended", "airbnb", "prettier"], | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"plugins": ["react"], | ||
"rules": { | ||
"no-restricted-syntax": "off", | ||
"no-use-before-define": ["error", { "functions": false }] | ||
} | ||
} |
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,10 +1,10 @@ | ||
{ | ||
"singleQuote": true, | ||
"jsxSingleQuote": true, | ||
"semi": false, | ||
"semi": true, | ||
"tabWidth": 2, | ||
"bracketSpacing": true, | ||
"jsxBracketSameLine": false, | ||
"arrowParens": "always", | ||
"trailingComma": "none" | ||
"trailingComma": "es5" | ||
} |
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,48 +1,50 @@ | ||
import { useState, useEffect, useRef } from 'react' | ||
import { useState, useEffect, useRef } from 'react'; | ||
|
||
const useResizeObserver = (option = 'contentRect') => { | ||
const ref = useRef(null) | ||
const [height, setHeight] = useState() | ||
const [width, setWidth] = useState() | ||
const ref = useRef(null); | ||
const [height, setHeight] = useState(); | ||
const [width, setWidth] = useState(); | ||
|
||
useEffect(() => { | ||
if (ref.current) { | ||
const observer = new ResizeObserver((entries) => { | ||
handleResize(entries) | ||
}) | ||
observer.observe(ref.current) | ||
handleResize(entries); | ||
}); | ||
observer.observe(ref.current); | ||
|
||
// Callback fired when component is unmounted | ||
return () => { | ||
observer.disconnect() | ||
} | ||
observer.disconnect(); | ||
}; | ||
} | ||
}) | ||
// Added this return for eslint rule -> no-consisten-return | ||
return undefined; | ||
}); | ||
|
||
const handleResize = (entries) => { | ||
for (let entry of entries) { | ||
function handleResize(entries) { | ||
for (const entry of entries) { | ||
if ( | ||
option === 'borderBoxSize' && | ||
entry.borderBoxSize && | ||
entry.borderBoxSize.length > 0 | ||
) { | ||
setHeight(entry.borderBoxSize[0].blockSize) | ||
setWidth(entry.borderBoxSize[0].inlineSize) | ||
setHeight(entry.borderBoxSize[0].blockSize); | ||
setWidth(entry.borderBoxSize[0].inlineSize); | ||
} else if ( | ||
option === 'contentBoxSize' && | ||
entry.contentBoxSize && | ||
entry.contentBoxSize.length > 0 | ||
) { | ||
setHeight(entry.contentBoxSize[0].blockSize) | ||
setWidth(entry.contentBoxSize[0].inlineSize) | ||
setHeight(entry.contentBoxSize[0].blockSize); | ||
setWidth(entry.contentBoxSize[0].inlineSize); | ||
} else { | ||
setHeight(entry.contentRect.height) | ||
setWidth(entry.contentRect.width) | ||
setHeight(entry.contentRect.height); | ||
setWidth(entry.contentRect.width); | ||
} | ||
} | ||
} | ||
|
||
return [ref, width, height] | ||
} | ||
return [ref, width, height]; | ||
}; | ||
|
||
export default useResizeObserver | ||
export default useResizeObserver; |