小编Jua*_*n41的帖子

<input> 标签上的属性 `reset` 值无效

我收到这个警告:

react-dom.development.js:86 警告:reset标签上的 prop 值无效。要么将其从元素中删除,要么传递一个字符串或数字值以将其保留在 DOM 中。详情请参见https://reactjs.org/link/attribute-behavior

这来自我的自定义挂钩:

import { useState } from 'react'

export const useField = (type) => {
  const [value, setValue] = useState('')

  const onChange = (event) => {
    setValue(event.target.value)
  }

  const reset = () => {
    setValue('')
  }

  return {
    type,
    value,
    onChange,
    reset
  }
}
Run Code Online (Sandbox Code Playgroud)

该钩子在组件中使用:

const CreateNew = (props) => {
  const content = useField('text')
  const author = useField('text')
  const info = useField('text')

  const navigate = useNavigate()

  const handleSubmit = (e) …
Run Code Online (Sandbox Code Playgroud)

html javascript reactjs react-hooks react-custom-hooks

1
推荐指数
1
解决办法
1558
查看次数