import React, { useState, useEffect, useQuery } from 'react'; import { Link, useParams } from 'react-router-dom'; import io from 'socket.io-client'; // 632b86aa55e76f7ddb1eae29 import { history } from '../history/'; import '../App.css'; import store from '../store'; import { actionAboutMe } from '../store/actions/action-aboutMe' import backgroundChat from '../img/back.JPG' import { useRef } from 'react'; import { actionSearchUser } from '../store/actions/action-search-user'; export const ChatInfoPage = ({ us, onSearchUser, match: { params: { _id } }, chats, getData, userName }) => { const [chatList, setChatList] = useState(chats || []) const [messageList, setMessageList] = useState([]) const [chatInfo, setChatInfo] = useState([]) const [searchUser, setSearchUser] = useState("") const [userAdd, setUserAdd] = useState("") const SearchUs = ( _id) => { onSearchUser(searchUser) setSearchUser('') const stD = store.dispatch(onSearchUser()) const userId = us console.log('1', stD) console.log('2', userId) console.log(store.getState()) } useEffect(() => { if (chats) { const activeChatId = window.location.pathname.split('/')[2] let activeChat = chats.filter((item) => item._id === activeChatId); console.log('mem', activeChat) setChatInfo(activeChat[0].members) } }, [chats]) useEffect(() => { async function getDataFunc() { const res = await getData(_id) setChatList(res.chats) setMessageList(res.chats?.message) setChatInfo(res.chats?.members) } getDataFunc() }, [_id]) function handleClick(_id) { const filteredChatList = chatList.filter((item) => item._id === _id) console.log(filteredChatList) setMessageList(filteredChatList[0].messages) } function chatInfoClick(_id) { const filteredChatList = chatList.filter((item) => item._id === _id) console.log(filteredChatList) setChatInfo(filteredChatList[0].members) } return ( <>

Members Add

setSearchUser(e.target.value)} className="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" />

Members:

{chatInfo /* chatInfo.length > 0 */ &&
    {chatInfo.map((item2, index) =>
  • {item2.login}

  • )}
}
) }