aboutsummaryrefslogtreecommitdiff
path: root/vnext/src
diff options
context:
space:
mode:
Diffstat (limited to 'vnext/src')
-rw-r--r--vnext/src/App.js2
-rw-r--r--vnext/src/components/Chat.js12
-rw-r--r--vnext/src/components/Thread.js8
3 files changed, 10 insertions, 12 deletions
diff --git a/vnext/src/App.js b/vnext/src/App.js
index 1493f27a..17f87e45 100644
--- a/vnext/src/App.js
+++ b/vnext/src/App.js
@@ -1,6 +1,4 @@
import React, { useState, useEffect } from 'react';
-import PropTypes from 'prop-types';
-import ReactRouterPropTypes from 'react-router-prop-types';
import { BrowserRouter as Router, Route, Link, Switch } from 'react-router-dom';
import qs from 'qs';
diff --git a/vnext/src/components/Chat.js b/vnext/src/components/Chat.js
index 8c1e2311..a1254a10 100644
--- a/vnext/src/components/Chat.js
+++ b/vnext/src/components/Chat.js
@@ -1,4 +1,4 @@
-import React, { useEffect, useState } from 'react';
+import React, { useEffect, useState, useCallback } from 'react';
import PropTypes from 'prop-types';
import ReactRouterPropTypes from 'react-router-prop-types';
import { UserType } from './Types';
@@ -25,9 +25,9 @@ export default function Chat(props) {
props.connection.removeEventListener('msg', onMessage);
}
};
- }, [props.connection.readyState]);
+ }, [props.connection, onMessage, loadChat, props.match.params.user]);
- let loadChat = (uname) => {
+ let loadChat = useCallback((uname) => {
const { hash } = props.visitor;
setChats([]);
if (hash && uname) {
@@ -36,16 +36,16 @@ export default function Chat(props) {
setChats(response.data);
});
}
- };
+ }, [props.visitor]);
- let onMessage = (json) => {
+ let onMessage = useCallback((json) => {
const msg = JSON.parse(json.data);
if (msg.user.uname === props.match.params.user) {
setChats((oldChat) => {
return [msg, ...oldChat];
});
}
- };
+ }, [props.match.params.user]);
let onSend = (template) => {
pm(template.to.uname, template.body)
diff --git a/vnext/src/components/Thread.js b/vnext/src/components/Thread.js
index 66b5fd62..e7ccb032 100644
--- a/vnext/src/components/Thread.js
+++ b/vnext/src/components/Thread.js
@@ -87,7 +87,7 @@ export default function Thread(props) {
useEffect(() => {
setActive(0);
loadReplies();
- }, []);
+ }, [loadReplies]);
useEffect(() => {
if (props.connection.addEventListener && message.mid) {
props.connection.addEventListener('msg', onReply);
@@ -96,8 +96,8 @@ export default function Thread(props) {
if (props.connection.removeEventListener && message.mid) {
props.connection.removeEventListener('msg', onReply);
}
- }
- }, [props.connection, message.mid]);
+ };
+ }, [props.connection, message.mid, onReply]);
let loadReplies = useCallback(() => {
document.body.scrollTop = 0;
@@ -122,7 +122,7 @@ export default function Thread(props) {
).catch(ex => {
console.log(ex);
});
- }, []);
+ }, [props.visitor, props.match.params]);
let onReply = useCallback((json) => {
const msg = JSON.parse(json.data);
if (msg.mid == message.mid) {