Improve variable naming

This commit is contained in:
Nikhil Nawgiri 2024-10-27 12:54:44 +01:00
parent a8064668b8
commit 0a138375dc
2 changed files with 12 additions and 12 deletions

View file

@ -4,11 +4,11 @@ import Search from './components/search/Search'
import jellyfin from './assets/jellyfin.svg'
import './App.css'
import SearchResults from './components/search/SearchResults';
import SearchResult from './components/search/SearchResult';
function App() {
const [searchString, setSearchString] = useState("");
const [searchResults, setSearchResults] = useState<{}[]>([]);
const [searchResult, setSearchResult] = useState<{}[]>([]);
const [itemChoiceByUser, setItemChoiceByUser] = useState({});
const [count, setCount] = useState(0)
@ -24,15 +24,15 @@ function App() {
Wishlist
</h1>
<Search
setSearchResults={setSearchResults}
setSearchResult={setSearchResult}
searchString={searchString}
setSearchString={setSearchString}
/>
</header>
<main>
<div>
<SearchResults
items={searchResults}
<SearchResult
items={searchResult}
/>
</div>
</main>

View file

@ -7,33 +7,33 @@ import debounce from "lodash/debounce";
import searchApiCall from "../../helper/omdbHelper.ts";
interface SearchProps {
setSearchResults: Function,
setSearchResult: Function,
setSearchString: Function,
searchString: string,
}
const Search = ({ setSearchResults, setSearchString, searchString }: SearchProps) => {
const Search = ({ setSearchResult, setSearchString, searchString }: SearchProps) => {
const inputRef = useRef() as MutableRefObject<HTMLInputElement>;
const debouncedSearch = useMemo(
() => debounce(() => {
searchApiCall({ searchString: searchString, setter: setSearchResults });
searchApiCall({ searchString: searchString, setter: setSearchResult });
}, 300),
[searchString, setSearchResults]
[searchString, setSearchResult]
);
useEffect(() => {
if (searchString.length > 0) {
debouncedSearch();
} else {
setSearchResults([]);
setSearchResult([]);
}
}, [searchString, debouncedSearch, setSearchResults]);
}, [searchString, debouncedSearch, setSearchResult]);
const resetSearchTerm = () => {
inputRef.current.focus();
setSearchString("");
setSearchResults([]);
setSearchResult([]);
};
return (