I got the problem in using React Hook – useDispatch()

React Hook "useDispatch" is called in function "loginForm" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks

I got this kind of message.
Attached code…

import React from 'react'
import { useDispatch} from 'react-redux'

const loginForm = () => {
  const dispatch = useDispatch()
  
  return (
    <div>lgoinForm</div>
  )
}

export default loginForm

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Rename loginForm to LoginForm (component should start with a capital letter).

I have tested your code and it works fine after naming the component correctly.

Read here and here

Solution 2

You can make the loginForm to useLoginForm it should be a custom hook name starting with use keyword.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply