mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-19 18:13:41 -05:00
web: use useCallback instead of useMemo
This commit is contained in:
parent
0dc278523a
commit
097caa7717
2 changed files with 5 additions and 5 deletions
|
@ -13,7 +13,7 @@
|
|||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import React, { use, useMemo } from "react"
|
||||
import React, { use, useCallback } from "react"
|
||||
import type { RoomID } from "../../api/types"
|
||||
import { useNonNullEventAsState } from "../../util/eventdispatcher.ts"
|
||||
import { ClientContext } from "../ClientContext.ts"
|
||||
|
@ -26,7 +26,7 @@ interface RoomListProps {
|
|||
|
||||
const RoomList = ({ setActiveRoom }: RoomListProps) => {
|
||||
const roomList = useNonNullEventAsState(use(ClientContext)!.store.roomList)
|
||||
const clickRoom = useMemo(() => (evt: React.MouseEvent) => {
|
||||
const clickRoom = useCallback((evt: React.MouseEvent) => {
|
||||
const roomID = evt.currentTarget.getAttribute("data-room-id")
|
||||
if (roomID) {
|
||||
setActiveRoom(roomID)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import { use, useEffect, useMemo, useRef } from "react"
|
||||
import { use, useCallback, useEffect, useRef } from "react"
|
||||
import { RoomStateStore } from "../../api/statestore.ts"
|
||||
import { useNonNullEventAsState } from "../../util/eventdispatcher.ts"
|
||||
import { ClientContext } from "../ClientContext.ts"
|
||||
|
@ -27,7 +27,7 @@ interface TimelineViewProps {
|
|||
const TimelineView = ({ room }: TimelineViewProps) => {
|
||||
const timeline = useNonNullEventAsState(room.timeline)
|
||||
const client = use(ClientContext)!
|
||||
const loadHistory = useMemo(() => () => {
|
||||
const loadHistory = useCallback(() => {
|
||||
client.loadMoreHistory(room.roomID)
|
||||
.catch(err => console.error("Failed to load history", err))
|
||||
}, [client, room.roomID])
|
||||
|
@ -39,7 +39,7 @@ const TimelineView = ({ room }: TimelineViewProps) => {
|
|||
|
||||
// When the user scrolls the timeline manually, remember if they were at the bottom,
|
||||
// so that we can keep them at the bottom when new events are added.
|
||||
const handleScroll = useMemo(() => () => {
|
||||
const handleScroll = useCallback(() => {
|
||||
if (!timelineViewRef.current) {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue