1- import { useEffect , useState } from 'react'
1+ import { useEffect , useMemo , useState } from 'react'
22import { Link , useLocation } from '@remix-run/react'
33import { observer } from 'mobx-react'
44import {
@@ -39,7 +39,6 @@ type ResearchArticleProps = {
3939
4040const ResearchArticle = observer (
4141 ( { research, publicUpdates } : ResearchArticleProps ) => {
42- const [ updates , setUpdates ] = useState ( publicUpdates )
4342 const location = useLocation ( )
4443 const researchStore = useResearchStore ( )
4544 const { aggregationsStore } = useCommonStores ( ) . stores
@@ -53,22 +52,18 @@ const ResearchArticle = observer(
5352 research . votedUsefulBy ?. length || 0 ,
5453 )
5554
56- useEffect ( ( ) => {
55+ const updates = useMemo ( ( ) => {
5756 // Only public updates (non draft) are server-side rendered.
5857 // But we still need to display the draft updates when the currentUser is the author/contributor.
5958 // Since the current user is only loaded client-side, we need to check and re-set the updates.
6059 if ( ! researchStore . activeUser ) {
61- return
60+ return publicUpdates
6261 }
6362
64- const authorUpdates = research . updates ?. filter ( ( update ) =>
63+ return research . updates ?. filter ( ( update ) =>
6564 researchUpdateStatusFilter ( research , update , researchStore . activeUser ) ,
6665 )
67-
68- if ( authorUpdates . length !== updates . length ) {
69- setUpdates ( authorUpdates )
70- }
71- } , [ researchStore . activeUser ] )
66+ } , [ researchStore . activeUser , publicUpdates , research . updates ] )
7267
7368 useEffect ( ( ) => {
7469 // This could be improved if we can load the user profile server-side
0 commit comments