diff --git a/superset-frontend/.eslintrc.js b/superset-frontend/.eslintrc.js index ed437f9cc..0ee38568f 100644 --- a/superset-frontend/.eslintrc.js +++ b/superset-frontend/.eslintrc.js @@ -17,7 +17,12 @@ * under the License. */ module.exports = { - extends: ['airbnb', 'prettier', 'prettier/react'], + extends: [ + 'airbnb', + 'prettier', + 'prettier/react', + 'plugin:react-hooks/recommended', + ], parser: 'babel-eslint', parserOptions: { ecmaFeatures: { diff --git a/superset-frontend/package-lock.json b/superset-frontend/package-lock.json index 6571e0090..9d7842556 100644 --- a/superset-frontend/package-lock.json +++ b/superset-frontend/package-lock.json @@ -25879,9 +25879,9 @@ } }, "eslint-plugin-react-hooks": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.1.0.tgz", - "integrity": "sha512-36zilUcDwDReiORXmcmTc6rRumu9JIM3WjSvV0nclHoUQ0CNrX866EwONvLR/UqaeqFutbAnVu8PEmctdo2SRQ==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.1.2.tgz", + "integrity": "sha512-ykUeqkGyUGgwTtk78C0o8UG2fzwmgJ0qxBGPp2WqRKsTwcLuVf01kTDRAtOsd4u6whX2XOC8749n2vPydP82fg==", "dev": true }, "eslint-scope": { diff --git a/superset-frontend/package.json b/superset-frontend/package.json index 61c67bbfa..033d2bbee 100644 --- a/superset-frontend/package.json +++ b/superset-frontend/package.json @@ -246,7 +246,7 @@ "eslint-plugin-no-only-tests": "^2.0.1", "eslint-plugin-prettier": "^3.1.3", "eslint-plugin-react": "^7.20.6", - "eslint-plugin-react-hooks": "^4.1.0", + "eslint-plugin-react-hooks": "^4.1.2", "exports-loader": "^0.7.0", "fetch-mock": "^7.7.3", "file-loader": "^6.0.0", diff --git a/superset-frontend/src/components/Select/WindowedSelect/WindowedMenuList.tsx b/superset-frontend/src/components/Select/WindowedSelect/WindowedMenuList.tsx index f3d4ca1fc..400ccde8e 100644 --- a/superset-frontend/src/components/Select/WindowedSelect/WindowedMenuList.tsx +++ b/superset-frontend/src/components/Select/WindowedSelect/WindowedMenuList.tsx @@ -21,8 +21,8 @@ import React, { useEffect, Component, FunctionComponent, - RefObject, ReactElement, + RefObject, } from 'react'; import { ListChildComponentProps, @@ -106,9 +106,11 @@ export default function WindowedMenuList({ } = props; const { // Expose react-window VariableSizeList instance and HTML elements - windowListRef = useRef(null), + windowListRef: windowListRef_, windowListInnerRef, } = selectProps; + const defaultWindowListRef = useRef(null); + const windowListRef = windowListRef_ || defaultWindowListRef; // try get default option height from theme configs let { optionHeight } = selectProps; @@ -118,7 +120,6 @@ export default function WindowedMenuList({ const itemCount = children.length; const totalHeight = optionHeight * itemCount; - const listRef: RefObject = windowListRef || useRef(null); const Row: FunctionComponent = ({ data, @@ -130,10 +131,10 @@ export default function WindowedMenuList({ useEffect(() => { const lastSelected = getLastSelected(children); - if (listRef.current && lastSelected) { - listRef.current.scrollToItem(lastSelected); + if (windowListRef.current && lastSelected) { + windowListRef.current.scrollToItem(lastSelected); } - }, [children]); + }, [children, windowListRef]); return ( ({ }, className, )} - ref={listRef} + ref={windowListRef} outerRef={innerRef} innerRef={windowListInnerRef} height={Math.min(totalHeight, maxHeight)}