最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - I got the problem in using React Hook - useDispatch() - Stack Overflow

programmeradmin1浏览0评论

React Hook "useDispatch" is called in function "loginForm" which is neither a React function ponent 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

React Hook "useDispatch" is called in function "loginForm" which is neither a React function ponent 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
Share Improve this question edited Jul 8, 2020 at 13:10 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Jul 8, 2020 at 3:57 Brian WangBrian Wang 831 silver badge8 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

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

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

Read here and here

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

发布评论

评论列表(0)

  1. 暂无评论