You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportfunctionContentComponent(){constscrollEl=useRef<HTMLDivElement>(null);const[distanceToBottom,setDistanceToBottom]=useState<number|null>(null);// handle scroll event function, when scroll trigger it.consthandleScroll=async()=>{// when distance to top less than 300pxif(message.length>0&&Number(scrollEl.current?.scrollTop)<300&&!loadingMessage&&hasMessage){// request API firstconst{ payload }=awaitasyncLoadMessage();constdistanceToTop=getTopSpace();dispatch(asyncLoadMessage(payload));// only when current position to top is 0px, need to reset scroll positionif(Number(distanceToTop)===0){setDistanceToBottom(getBottomSpace());}}};useLayoutEffect(()=>{if(scrollEl.current?.scrollTop!==undefined&&distanceToBottom!==null){scrollEl.current.scrollTop=scrollEl.current.scrollHeight-distanceToBottom;setDistanceToBottom(null);}},[distanceToBottom]);return(<divclassName="overflow-y-auto flex-1 relative px-3.5 py-0"ref={scrollEl}onScroll={throttle(handleScroll)}><TipComponent/>{message.map((msg)=>(<MessageComponentkey={msg._id}data={msg}/>))}</div>)}
The text was updated successfully, but these errors were encountered:
Screen.Recording.2023-04-24.at.3.27.20.AM.mov
这样处理的原因是因为, 当你滑到最顶部再 push 元素, 会直接定位到顶部, 需要
scrollIntoView
到之前的位置.The text was updated successfully, but these errors were encountered: