1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Update the "results" state if "initialResultsState" array length is different (#15270)

This commit is contained in:
Daniel 2022-07-18 16:30:36 +02:00 committed by GitHub
parent d8a1b3bcc7
commit 2744eaf760
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
import React, { useState, useRef } from 'react';
import React, { useState, useRef, useMemo, useEffect } from 'react';
import PropTypes from 'prop-types';
import ItemList from './item-list';
import ListItemSearch from './list-item-search';
@ -22,7 +22,14 @@ export default function SearchableItemList({
}) {
const itemListRef = useRef();
const [results, setResults] = useState(defaultToAll ? itemsToSearch : []);
const initialResultsState = useMemo(() => {
return defaultToAll ? itemsToSearch : [];
}, [defaultToAll, itemsToSearch]);
const [results, setResults] = useState(initialResultsState);
useEffect(() => {
setResults(initialResultsState);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [initialResultsState.length]);
const [searchQuery, setSearchQuery] = useState('');
return (