@@ -22,44 +22,47 @@ export const useFetchReactions = ({
2222 const [ next , setNext ] = useState < string | undefined > ( undefined ) ;
2323 const messageId = message ?. id ;
2424
25- const { client, enableOfflineSupport } = useChatContext ( ) ;
25+ const { client } = useChatContext ( ) ;
2626
2727 const sortString = useMemo ( ( ) => JSON . stringify ( sort ) , [ sort ] ) ;
2828
29- const fetchReactions = useCallback ( async ( ) => {
30- if ( ! messageId ) {
31- return ;
32- }
33- try {
34- const response = await client . queryReactions (
35- messageId ,
36- reactionType ? { type : reactionType } : { } ,
37- sort ,
38- { limit, next } ,
39- ) ;
40- if ( response ) {
41- setReactions ( ( prevReactions ) =>
42- next ? [ ...prevReactions , ...response . reactions ] : response . reactions ,
29+ const fetchReactions = useCallback (
30+ async ( next : string | undefined ) => {
31+ if ( ! messageId ) {
32+ return ;
33+ }
34+ try {
35+ const response = await client . queryReactions (
36+ messageId ,
37+ reactionType ? { type : reactionType } : { } ,
38+ sort ,
39+ { limit, next } ,
4340 ) ;
44- setNext ( response . next ) ;
45- setLoading ( false ) ;
41+ if ( response ) {
42+ setNext ( response . next ) ;
43+
44+ setReactions ( ( prevReactions ) =>
45+ next ? [ ...prevReactions , ...response . reactions ] : response . reactions ,
46+ ) ;
47+ setLoading ( false ) ;
48+ }
49+ } catch ( error ) {
50+ console . log ( 'Error fetching reactions: ' , error ) ;
4651 }
47- } catch ( error ) {
48- console . log ( 'Error fetching reactions: ' , error ) ;
49- }
50- // eslint-disable-next-line react-hooks/exhaustive-deps
51- } , [ client , messageId , reactionType , sortString , next , limit , enableOfflineSupport ] ) ;
52+ } ,
53+ [ messageId , client , reactionType , sort , limit ] ,
54+ ) ;
5255
5356 const loadNextPage = useCallback ( async ( ) => {
5457 if ( next ) {
55- await fetchReactions ( ) ;
58+ await fetchReactions ( next ) ;
5659 }
5760 } , [ fetchReactions , next ] ) ;
5861
5962 useEffect ( ( ) => {
6063 setReactions ( [ ] ) ;
6164 setNext ( undefined ) ;
62- fetchReactions ( ) ;
65+ fetchReactions ( undefined ) ;
6366 } , [ fetchReactions , messageId , reactionType , sortString ] ) ;
6467
6568 useEffect ( ( ) => {
0 commit comments