Skip to content

Commit

Permalink
Memoize filters
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoerner committed Oct 8, 2024
1 parent 7cd19c3 commit ba4559b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
17 changes: 10 additions & 7 deletions src/pages/agent/Agent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, Fragment } from 'react'
import { FC, Fragment, useMemo } from 'react'
import { useParams } from 'react-router-dom'
import { Helmet } from 'react-helmet'
import { useTranslation } from 'react-i18next'
Expand All @@ -15,12 +15,15 @@ const Agent: FC = () => {
const { t } = useTranslation()
const title = `Agent ${agentName}`

const initialFilter: BannerFilter = {
author: agentName,
orderBy: 'created',
orderDirection: 'DESC',
online: true,
}
const initialFilter: BannerFilter = useMemo(
() => ({
author: agentName,
orderBy: 'created',
orderDirection: 'DESC',
online: true,
}),
[agentName]
)

return (
<Fragment>
Expand Down
21 changes: 12 additions & 9 deletions src/pages/events/Events.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react'
import { FC, useMemo } from 'react'
import { Helmet } from 'react-helmet'
import { useTranslation } from 'react-i18next'
import FooterMain from '../../components/footer-main'
Expand All @@ -9,15 +9,18 @@ const Events: FC = () => {
const { t } = useTranslation()
const title = t('events.title')

const currentTimestamp = new Date().toISOString()
const currentTimestamp = useMemo(() => new Date().toISOString(), [])

const initialFilter: BannerFilter = {
minEventTimestamp: currentTimestamp,
maxEventTimestamp: currentTimestamp,
orderBy: 'created',
orderDirection: 'DESC',
online: true,
}
const initialFilter: BannerFilter = useMemo(
() => ({
minEventTimestamp: currentTimestamp,
maxEventTimestamp: currentTimestamp,
orderBy: 'created',
orderDirection: 'DESC',
online: true,
}),
[currentTimestamp]
)

return (
<>
Expand Down
17 changes: 10 additions & 7 deletions src/pages/user-banner-list/UserBannerList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, Fragment } from 'react'
import { FC, Fragment, useMemo } from 'react'
import { useParams } from 'react-router-dom'
import { Helmet } from 'react-helmet'
import { useTranslation } from 'react-i18next'
Expand All @@ -18,12 +18,15 @@ const UserBannerList: FC = () => {
const { t } = useTranslation()
const title = t('banners.mine', { type: getBannerListTypeText(listType) })

const initialFilter: BannerFilter = {
listTypes: listType,
orderBy: 'listAdded',
orderDirection: 'DESC',
online: undefined,
}
const initialFilter: BannerFilter = useMemo(
() => ({
listTypes: listType,
orderBy: 'listAdded',
orderDirection: 'DESC',
online: undefined,
}),
[listType]
)

return (
<Fragment>
Expand Down

0 comments on commit ba4559b

Please sign in to comment.