change not to update state object

Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
This commit is contained in:
yamashush 2024-01-18 19:30:09 +09:00 committed by Tilman Vatteroth
parent cd01deca67
commit 8aa913c179

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { useApplicationState } from '../../../../../../hooks/common/use-application-state' import { useApplicationState } from '../../../../../../hooks/common/use-application-state'
import type { Alias } from '../../../../../../api/alias/types'
import type { ApplicationState } from '../../../../../../redux/application-state' import type { ApplicationState } from '../../../../../../redux/application-state'
import { AliasesListEntry } from './aliases-list-entry' import { AliasesListEntry } from './aliases-list-entry'
import React, { Fragment, useMemo } from 'react' import React, { Fragment, useMemo } from 'react'
@ -13,13 +14,12 @@ import React, { Fragment, useMemo } from 'react'
*/ */
export const AliasesList: React.FC = () => { export const AliasesList: React.FC = () => {
const aliases = useApplicationState((state: ApplicationState) => state.noteDetails?.aliases) const aliases = useApplicationState((state: ApplicationState) => state.noteDetails?.aliases)
const aliasesDom = useMemo(() => { const aliasesDom = useMemo(() => {
return aliases === undefined return aliases === undefined
? null ? null
: aliases : Object.assign([], aliases)
.sort((a, b) => a.name.localeCompare(b.name)) .sort((a: Alias, b: Alias) => a.name.localeCompare(b.name))
.map((alias) => <AliasesListEntry alias={alias} key={alias.name} />) .map((alias: Alias) => <AliasesListEntry alias={alias} key={alias.name} />)
}, [aliases]) }, [aliases])
return <Fragment>{aliasesDom}</Fragment> return <Fragment>{aliasesDom}</Fragment>