Skip to content

Instantly share code, notes, and snippets.

@meness
meness / usage.tsx
Created Apr 25, 2022
React Hook: useComponentDidUpdate()
View usage.tsx
const useComponentDidUpdate = useGetSnapshotBeforeUpdate(
(_prevProps, prevState) => {
if (!messagesWrapperRef.current || !messages.data || !prevState) return undefined;
if (messagesWrapperRef.current.scrollHeight > (prevState.scrollHeight || 0)) {
return prevState.scrollHeight;
}
return undefined;
},