Error: Invalid hook call. guys please helpme

import React, { useState ,useEffect} from 'react'
import "./Chat.css"
import { Avatar ,  IconButton } from '@material-ui/core'
import MoreVertIcon from '@material-ui/icons/MoreVert';
import SearchOutlinedIcon from '@material-ui/icons/SearchOutlined';
import AttachFileIcon from '@material-ui/icons/AttachFile';
import EmojiEmotionsOutlinedIcon from '@material-ui/icons/EmojiEmotionsOutlined';
import MicIcon from '@material-ui/icons/Mic';
import { useParams } from "react-router-dom";
import db from './firebase';
function Chat(props) {
    const [input, setInput] = useState('')
    const [seed, setSeed] = useState('');
    const { roomId } = useParams();
    const [roomName, setRoomName] =useState("")
    useEffect(() => {
      if(roomId) {
        .onSnapshot(snapshot =>(
    }, [roomId] )
    useEffect(() => {
        setSeed(Math.floor(Math.random() * 5000));
      }, [])

    const sendMessage = (event) => {
    return <div className="chat"> 

      <div className="chat__header">
      <Avatar src={`${seed}.svg`} />
      <div className="chat__headerInfo">
      <p> last message....</p>

      <div className="chat__headerRight">
      <SearchOutlinedIcon />

      <div className="chat__body">
      <p className={`chat__message ${true &&
      <span className="chat__name">Ashu</span>
      Hey guys
      <span className ="chat__timestamp">2:52pm;

      <div className="chat__footer">
      <input value={input} 
      onChange={(event) => setInput(}
      placeholder="Type a message..."
      type="text" />
      <button onClick="{sendMessage}" type="submit">Send a message</button>

export default Chat

Please help!!!!!. whenever I tries to use {useparams}
I fails and anerror is displayed:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app
    See for tips about how to debug and fix this problem.

Please help me How to debug it

30 thoughts on “Error: Invalid hook call. guys please helpme”

  1. It seems like dependency react-router missing. Have you added it ? Please look into your package.json file. if react-router is missing then you need to add this package.

  2. I don’t think you broke the rules of hooks check if You have mismatching versions of React and React DOM or you have more than one copy of react in the same app


Leave a Comment