Skip to content

Instantly share code, notes, and snippets.

View meness's full-sized avatar
:octocat:
I may be slow to respond.

Alex meness

:octocat:
I may be slow to respond.
View GitHub Profile
@meness
meness / usage.tsx
Created April 25, 2022 09:12
React Hook: useComponentDidUpdate()
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;
},