aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/components
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-04-08 12:28:42 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:54 +0300
commitbbfb81c2bc8d6afba550299e7138eeb2c58956d3 (patch)
tree7bac2ebe816e577c38040ccd5a07fb36bbb249e9 /vnext/src/components
parent9c0f90c01b918cc56ac996eebdc21bf58ba07bb1 (diff)
Pass EventSource connection to child components
Diffstat (limited to 'vnext/src/components')
-rw-r--r--vnext/src/components/Thread.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/vnext/src/components/Thread.js b/vnext/src/components/Thread.js
index 4946cf5f..d61fd87f 100644
--- a/vnext/src/components/Thread.js
+++ b/vnext/src/components/Thread.js
@@ -22,8 +22,12 @@ export default function Thread(props) {
const [loading, setLoading] = useState(false);
const [active, setActive] = useState(0);
useEffect(() => {
+ props.connection.addEventListener('msg', onReply);
setActive(0);
loadReplies();
+ return () => {
+ props.connection.removeEventListener('msg', onReply);
+ }
}, []);
let loadReplies = () => {
document.body.scrollTop = 0;
@@ -49,11 +53,10 @@ export default function Thread(props) {
console.log(ex);
});
}
- let onReply = (msg) => {
+ let onReply = (json) => {
+ const msg = JSON.parse(json);
if (msg.mid == message.mid) {
- this.setState({
- replies: [...this.state.replies, msg]
- });
+ setReplies([...this.state.replies, msg]);
}
}
let postComment = (template) => {