diff options
author | Vitaly Takmazov | 2019-10-24 13:16:38 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-13 10:37:55 +0300 |
commit | 8bc4d932b20079c01045248fc02b2726ba73775c (patch) | |
tree | b05d373bb324d76c276eee12898b78ac2ea71cf8 /vnext/src/ui/Thread.js | |
parent | 1baee0fc63ba8228d009a11c0211dca8fbef09bf (diff) |
Correctly change state from useEffect without dependencies
Diffstat (limited to 'vnext/src/ui/Thread.js')
-rw-r--r-- | vnext/src/ui/Thread.js | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/vnext/src/ui/Thread.js b/vnext/src/ui/Thread.js index cbd40c4c..2e07cd0e 100644 --- a/vnext/src/ui/Thread.js +++ b/vnext/src/ui/Thread.js @@ -46,17 +46,20 @@ function Comment({ msg, draft, visitor, active, setActive, onStartEditing, postC }, []); useEffect(() => { isMounted = true; - if (author.uri) { - fetchUserUri(author.uri).then(response => { - if (isMounted) { - setAuthor(response.data); - } - }); - } + setAuthor(previous => { + if (previous.uri) { + fetchUserUri(previous.uri).then(response => { + if (isMounted) { + return response.data; + } + }); + } + return previous; + }); return () => { isMounted = false; }; - }, [author.uri]); + }, []); return ( <div style={chatItemStyle(visitor, msg)}> <div className="msg-header"> |