diff --git a/src/web/search/CommonDisplay.tsx b/src/web/search/CommonDisplay.tsx index a4e5666..a7c7f4e 100644 --- a/src/web/search/CommonDisplay.tsx +++ b/src/web/search/CommonDisplay.tsx @@ -1,5 +1,5 @@ import { useRouter } from 'next/router'; -import React, { Fragment, useEffect, useState } from 'react'; +import React, { DependencyList, EffectCallback, Fragment, useEffect, useState } from 'react'; import ButtonsForStars from '../display/buttonsForStars'; import Form from '../display/form'; @@ -44,6 +44,17 @@ export const defaultQueryParameters: QueryParametersWithoutNum = { }; export const defaultNumDisplay = 21; +const useNoInitialEffect = (effect: EffectCallback, deps: DependencyList) => { + const initial = React.useRef(true); + useEffect(() => { + if (initial.current) { + initial.current = false; + return; + } + return effect(); + }, deps); +}; + /* Body */ const CommonDisplay: React.FC = ({ defaultResults, @@ -159,9 +170,9 @@ const CommonDisplay: React.FC = ({ }); }; - useEffect(updateRoute, [numDisplay]); + useNoInitialEffect(updateRoute, [numDisplay]); - useEffect(() => { + useNoInitialEffect(() => { setResults([]); let newTimeoutId = setTimeout(() => { updateRoute();