From 841ec978bae3297357c3157a3adf846648771770 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 14 Nov 2019 13:44:52 +0300 Subject: react-router-dom hooks --- vnext/src/ui/Thread.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'vnext/src/ui/Thread.js') diff --git a/vnext/src/ui/Thread.js b/vnext/src/ui/Thread.js index 63bb2dd6..4f53c4af 100644 --- a/vnext/src/ui/Thread.js +++ b/vnext/src/ui/Thread.js @@ -1,4 +1,5 @@ import React, { useEffect, useState, useRef, useCallback } from 'react'; +import { useLocation, useParams } from 'react-router-dom'; import Message from './Message'; import MessageInput from './MessageInput'; @@ -11,7 +12,7 @@ import { format, embedUrls } from '../utils/embed'; import { getMessages, comment, update, markReadTracker, fetchUserUri, updateAvatar } from '../api'; -import { bubbleStyle, chatItemStyle } from './helpers/BubbleStyle'; +import { chatItemStyle } from './helpers/BubbleStyle'; import './Thread.css'; @@ -118,21 +119,21 @@ function Comment({ msg, draft, visitor, active, setActive, onStartEditing, postC /** * @param {{ - match: import('react-router').match, - location: import('history').Location, visitor: import('../api').SecureUser connection: EventSource }} props */ export default function Thread(props) { - const [message, setMessage] = useState((props.location.state || {}).msg || {}); + const location = useLocation(); + const params = useParams(); + const [message, setMessage] = useState((location.state || {}).msg || {}); const [replies, setReplies] = useState([]); const [loading, setLoading] = useState(false); const [active, setActive] = useState(0); const [editing, setEditing] = useState(emptyMessage); const [hash, setHash] = useState(props.visitor.hash); - const { mid } = props.match.params; + const { mid } = params; let loadReplies = useCallback(() => { document.body.scrollTop = 0; @@ -217,7 +218,10 @@ export default function Thread(props) { )) : ( <> - {Array(loaders).fill().map((it, i) => )} + { + // @ts-ignore + Array(loaders).fill().map((it, i) => ) + } ) } -- cgit v1.2.3