0

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
skyboyer
  • 19,620
  • 7
  • 50
  • 62
Brian Wang
  • 73
  • 7

2 Answers2

3

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

gdh
  • 11,691
  • 2
  • 11
  • 25
0

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