feat: more efficient filter with use memo

This commit is contained in:
RadoslavDimchev 2023-11-14 01:30:12 +02:00
parent f3b985713a
commit c47de2c6d1
1 changed files with 10 additions and 13 deletions

View File

@ -1,6 +1,6 @@
import { Checkbox, DropdownMenu, Text } from '@status-im/components'
import { OptionsIcon, SortIcon } from '@status-im/icons'
import { useEffect, useState } from 'react'
import { useMemo, useState } from 'react'
import { YStack, XStack, Stack } from 'tamagui'
import ValidatorProfile from '../../../components/General/ValidatorProfile'
@ -63,19 +63,16 @@ type ManagementTableProps = {
}
const ManagementTable = ({ tab }: ManagementTableProps) => {
const [currentValidators, setCurrentValidators] = useState(validators)
const [searchValue, setSearchValue] = useState('')
useEffect(() => {
setCurrentValidators(
validators
.filter(validator => validator.status === tab)
.filter(
validator =>
validator.number.toString().includes(searchValue) ||
validator.address.includes(searchValue),
),
)
const filteredValidators = useMemo(() => {
return validators
.filter(validator => validator.status === tab)
.filter(
validator =>
validator.number.toString().includes(searchValue) ||
validator.address.includes(searchValue),
)
}, [tab, searchValue])
const changeSearchValue = (value: string) => {
@ -172,7 +169,7 @@ const ManagementTable = ({ tab }: ManagementTableProps) => {
</tr>
</thead>
<tbody>
{currentValidators.map((validator, index) => (
{filteredValidators.map((validator, index) => (
<tr key={index}>
<td>
<Checkbox id={index.toString()} variant="outline" />