1

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
  • 22,209
  • 7
  • 57
  • 64
Brian Wang
  • 83
  • 1
  • 7

2 Answers2

4

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
  • 13,114
  • 2
  • 16
  • 28
1

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