[eslint]
src\pages\question\Edit\ComponentLib.tsx
Line 13:20: React Hook "useDispatch" is called in function "genComponent" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use" react-hooks/rules-of-hooks
Line 15:23: React Hook "useCallback" is called in function "genComponent" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use" react-hooks/rules-of-hooks
Search for the keywords to learn more about each error.
这个 错误是因为eslint 配置问题还是改版了?
以下是代码为拷贝老师的
import React, { FC, useCallback } from 'react'
import { nanoid } from 'nanoid'
import { Typography } from 'antd'
import { useDispatch } from 'react-redux'
import { componentConfGroup, ComponentConfType } from '../../../components/QuestionComponents'
import { addComponent } from '../../../store/componentsReducer'
import styles from './ComponentLib.module.scss'
const { Title } = Typography
function genComponent(c: ComponentConfType) {
const { title, type, Component, defaultProps } = c
const dispatch = useDispatch()
const handleClick = useCallback(() => {
dispatch(
addComponent({
fe_id: nanoid(), // 前端生成的 id
title,
type,
props: defaultProps,
})
)
}, [])
return (
<div key={type} className={styles.wrapper} onClick={handleClick}>
<div className={styles.component}>
<Component />
</div>
</div>
)
}
const Lib: FC = () => {
return (
<>
{componentConfGroup.map((group, index) => {
const { groupId, groupName, components } = group
return (
<div key={groupId}>
<Title level={3} style={{ fontSize: '16px', marginTop: index > 0 ? '20px' : '0' }}>
{groupName}
</Title>
<div>{components.map(c => genComponent(c))}</div>
</div>
)
})}
</>
)
}
export default Lib
React18+TS4+Antd5+Next.js13 ,B端+C 端,完整业务
了解课程