From e89107a8a1127945371c4bc64b38753424942e03 Mon Sep 17 00:00:00 2001 From: erik-sn Date: Fri, 23 Oct 2020 18:28:09 -0400 Subject: [PATCH] optimize tweet list to not re-render unless tweets change --- phone/src/apps/twitter/components/tweet/TweetList.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phone/src/apps/twitter/components/tweet/TweetList.tsx b/phone/src/apps/twitter/components/tweet/TweetList.tsx index 9b1e119..539c5e5 100644 --- a/phone/src/apps/twitter/components/tweet/TweetList.tsx +++ b/phone/src/apps/twitter/components/tweet/TweetList.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useState, memo } from "react"; import { List } from "../../../../ui/components/List"; import Tweet from "./Tweet"; @@ -21,7 +21,9 @@ export function TweetList({ tweets }) { // another flash to the tweets screen. const hasLoaded = tweets && minimumLoadPassed; + if (!hasLoaded) return ; + console.log(tweets.length); return ( {tweets.map((tweet) => ( @@ -31,4 +33,4 @@ export function TweetList({ tweets }) { ); } -export default TweetList; +export default memo(TweetList); // only re-render if our tweets change