File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { useEffect , useRef } from 'react'
2
+
3
+ export function useScrollToBottom < T extends HTMLElement > ( ) {
4
+ const ref = useRef < T > ( null )
5
+
6
+ useEffect ( ( ) => {
7
+ if ( ref . current ) {
8
+ ref . current . scrollTop = ref . current . scrollHeight
9
+ }
10
+ } , [ ] )
11
+
12
+ return ref
13
+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { Separator } from '~components/Separator'
7
7
import { Typo11 , Typo15 } from '~components/Typo'
8
8
import { useModalStore } from '~stores/modalStore'
9
9
import * as S from './styles'
10
+ import { useScrollToBottom } from '~hooks/useScrollToBottom'
10
11
11
12
type ChatModalProps = {
12
13
userId : string
@@ -15,9 +16,10 @@ type ChatModalProps = {
15
16
export default function ChatModal ( { userId } : ChatModalProps ) {
16
17
const { popModal } = useModalStore ( )
17
18
console . log ( 'ChatModal' , userId ) //todo fetch by userId
19
+ const ref = useScrollToBottom < HTMLDivElement > ( )
18
20
19
21
return (
20
- < S . ChatModal >
22
+ < S . ChatModal ref = { ref } >
21
23
< Header type = 'lg' prevBtn onClickPrev = { popModal } >
22
24
< S . ProfileWrapper >
23
25
< Profile $size = { 40 } $src = '' userId = { userId } />
You can’t perform that action at this time.
0 commit comments