无法使用React Hooks渲染功能组件

时间:2020-03-11 20:14:16

标签: javascript reactjs react-hooks

我是新来反应钩子的人。我正在尝试将以下组件用作ReactTable组件中某一列的过滤器输入元素。

import React, { useState } from 'react'
import DatePicker from 'material-ui/DatePicker/DatePickerDialog'

import '../styles/style.less'

export default function DateRange({ startLabel = 'From', endLabel = 'To' } = {}) {
  const [open, setOpen] = useState(false)

  return (
    <div className="date-range">
      <input type="text" placeholder={startLabel} onClick={() => setOpen(true)} />
      <input type="text" placeholder={endLabel} />
      <DatePicker open={open} />
    </div>
  )
}

但是渲染失败并出现以下错误:

Uncaught Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app

0 个答案:

没有答案