Commit fa67aadc authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed react hook warnings.

parent 6677d66e
module.exports = {
"extends": ["standard", "plugin:react/recommended"],
"extends": [
"standard",
"plugin:react/recommended",
"plugin:react-hooks/recommended"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
......@@ -13,7 +17,8 @@ module.exports = {
},
"rules": {
"space-before-function-paren": ["error", "never"],
"camelcase": [0]
"camelcase": [0],
"react-hooks/exhaustive-deps": "off"
},
"settings": {
"react": {
......
......@@ -102,7 +102,7 @@ export default function About() {
makeClickable('search', () => {
history.push('/search')
})
}, [svg])
}, [svg, makeClickable, setText, history])
useEffect(() => {
const statistics = (info && info.statistics) || {}
......@@ -130,7 +130,7 @@ export default function About() {
value('n_calculations', 'results'),
value('n_quantities', 'quantities')
])
}, [svg, info])
}, [svg, info, setText])
return <div className={classes.root}>
<Grid className={classes.container} container spacing={2}>
......
......@@ -506,6 +506,8 @@ class App extends React.PureComponent {
if (props.match || route.exists) {
route.exists = true
return <route.component visible={props.match && true} {...props} />
} else {
return ''
}
} else {
return props.match && <route.component {...props} />
......
......@@ -53,7 +53,7 @@ export default function DatasetPage() {
setDataset({})
raiseError(error)
})
}, [location.pathname, api])
}, [datasetId, location.pathname, api, raiseError])
if (!dataset) {
return <div>loading...</div>
......
......@@ -706,14 +706,14 @@ export function DisableOnLoading({children}) {
const enable = loading ? 'none' : ''
containerRef.current.style.pointerEvents = enable
containerRef.current.style.userSelects = enable
}, [api])
}, [])
useEffect(() => {
api.onLoading(handleLoading)
return () => {
api.removeOnLoading(handleLoading)
}
}, [])
}, [api, handleLoading])
return <div ref={containerRef}>{children}</div>
}
......
......@@ -9,6 +9,7 @@ export function DFTMethodVisualizations(props) {
const {response: {statistics, metric}, setStatistics} = useContext(searchContext)
useEffect(() => {
setStatistics(['dft.code_name', 'dft.basis_set', 'dft.xc_functional'])
// eslint-disable-next-line
}, [])
if (statistics.code_name && info) {
......@@ -47,6 +48,7 @@ export function DFTSystemVisualizations(props) {
const {response: {statistics, metric}, setStatistics} = useContext(searchContext)
useEffect(() => {
setStatistics(['dft.labels_springer_compound_class', 'dft.system', 'dft.crystal_system', 'dft.compound_type'])
// eslint-disable-next-line
}, [])
if (statistics.code_name && info) {
......@@ -156,6 +158,7 @@ export function DFTPropertyVisualizations(props) {
'dft.searchable_quantities',
'dft.labels_springer_classification'
])
// eslint-disable-next-line
}, [])
if (statistics.code_name && info) {
......
......@@ -7,7 +7,9 @@ export default function EMSVisualizations(props) {
const {setStatistics} = useContext(searchContext)
useEffect(() => {
setStatistics(['ems.method', 'ems.probing_method', 'ems.sample_microstructure', 'ems.sample_constituents'])
// eslint-disable-next-line
}, [])
return (
<Grid container spacing={2}>
<Grid item xs={6}>
......
......@@ -91,7 +91,7 @@ export default function MetaInfoBrowser({visible}) {
api.getInfo().then(info => {
setPackages(info.metainfo_packages)
}).catch(raiseError)
}, [api])
}, [api, raiseError])
useEffect(() => {
api.getMetaInfo(pkg).then(metainfos => {
......@@ -102,7 +102,7 @@ export default function MetaInfoBrowser({visible}) {
setMetainfos(metainfos)
}
}).catch(raiseError)
}, [pkg, metainfoName, api])
}, [pkg, metainfoName, api, history, raiseError])
const handleSelectedPackageChanged = event => {
history.push(`/metainfo/${event.target.value}/section_run`)
......
......@@ -224,6 +224,7 @@ function UsersVisualization() {
const {setStatistics} = useContext(searchContext)
useEffect(() => {
setStatistics(['uploader'])
// eslint-disable-next-line
}, [])
return <div>
<UploadsHistogram tooltips />
......@@ -236,6 +237,7 @@ function ElementsVisualization(props) {
const {response: {statistics, metric}, query, setQuery, setStatistics} = useContext(searchContext)
useEffect(() => {
setStatistics(['atoms'])
// eslint-disable-next-line
}, [])
const handleExclusiveChanged = () => {
......@@ -480,6 +482,7 @@ function SearchResults({availableTabs = ['entries'], initialTab = 'entries', res
if (openTab !== 'entries') {
handleTabChange(openTab)
}
// eslint-disable-next-line
}, [])
return <div className={classes.root}>
......@@ -539,7 +542,7 @@ const useScroll = (apiGroupName, afterParameterName) => {
const requestParameters = {}
requestParameters[apiAfterParameterName] = queryAfterParameter
setRequestParameters(requestParameters)
}, [queryAfterParameter, setRequestParameters]
}, [queryAfterParameter, setRequestParameters, apiAfterParameterName]
)
const responseGroup = response[`${apiGroupName}_grouped`]
......
......@@ -65,7 +65,7 @@ export default function SearchBar() {
const handleOptimadeEntered = useCallback(query => {
setQuery({'dft.optimade': query})
})
}, [setQuery])
let helperText = ''
if (error) {
......@@ -119,7 +119,7 @@ export default function SearchBar() {
setLoading(false)
})
}, 200)
}, [api, suggestionsTimerRef, apiQuery])
}, [api, suggestionsTimerRef, apiQuery, loading, setLoading])
const handleInputChange = useCallback((event, value, reason) => {
if (reason === 'input') {
......@@ -132,7 +132,7 @@ export default function SearchBar() {
setOptions(defaultOptions)
}
}
}, [loadOptions])
}, [loadOptions, defaultOptions])
const handleChange = (event, entries) => {
const newQuery = entries.reduce((query, entry) => {
......@@ -172,7 +172,7 @@ export default function SearchBar() {
if (!open) {
setOptions(defaultOptions)
}
}, [open])
}, [open, defaultOptions])
const commonTextFieldProps = params => ({
error: !!error,
......
import React, { useState, useContext, useEffect, useRef, useCallback } from 'react'
import React, { useState, useContext, useEffect, useRef, useCallback, useMemo } from 'react'
import PropTypes from 'prop-types'
import hash from 'object-hash'
import { errorContext } from '../errors'
......@@ -71,7 +71,7 @@ export const searchContext = React.createContext()
*/
export default function SearchContext({initialRequest, initialQuery, query, children}) {
const defaultStatistics = [] // ['atoms', 'authors'] TODO
const emptyResponse = {
const emptyResponse = useMemo(() => ({
statistics: {
total: {
all: {}
......@@ -85,7 +85,7 @@ export default function SearchContext({initialRequest, initialQuery, query, chil
order_by: 'upload_time'
},
metric: domains.dft.defaultSearchMetric
}
}), [])
const {api} = useContext(apiContext)
const {raiseError} = useContext(errorContext)
......@@ -175,7 +175,7 @@ export default function SearchContext({initialRequest, initialQuery, query, chil
raiseError(error)
}
})
}, [requestRef, setResponse, api])
}, [requestRef, setResponse, api, raiseError, emptyResponse, initialQuery, initialRequest, query])
// The following are various callbacks that can be used by children to update the
// request and implicitly trigger a search request to the API. The implicit triggering
......@@ -204,6 +204,7 @@ export default function SearchContext({initialRequest, initialQuery, query, chil
const setStatistics = useCallback(statistics => {
requestRef.current.statistics = [...statistics, ...defaultStatistics].filter(onlyUnique)
// eslint-disable-next-line
}, [requestRef])
const setGroups = useCallback(groups => {
......
......@@ -49,7 +49,7 @@ export default function UploadsHistogram({title = 'Uploads over time', initialSc
return () => {
setDateHistogram(false)
}
}, [])
}, [setDateHistogram])
useLayoutEffect(() => {
fromTimeFieldRef.current.value = Dates.FormDate(query.from_time || Dates.dateHistogramStartDate)
......@@ -202,7 +202,7 @@ export default function UploadsHistogram({title = 'Uploads over time', initialSc
setQuery({[key]: value})
} catch (error) {
}
})
}, [setQuery])
return <Card classes={{root: classes.root}}>
<CardHeader
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment