在函数“ AAA”中调用React Hook“ useState”,该函数既不是React函数组件也不是自定义的React Hook函数

时间:2019-09-26 05:59:54

标签: reactjs typescript function react-hooks

此代码段出现此错误。

const AB= () => {

  const [A, setA] = useState<AT| null>(null);
  const [B, setB] = useState<string>('0px');

..more}

1 个答案:

答案 0 :(得分:2)

使用Pascal大小写作为组件名称,如果尚未导入,则导入react和useState。

import React, { useState } from "react";
import ReactDOM from "react-dom";

const KlageHome = () => {
  const [matrikkelnummer, setMatrikkelnummer] = useState(null); 
  const [panelHeight, setPanelHeight] = useState('0px')
  return (
    <div>{panelHeight}</div>
  )
}

const rootElement = document.getElementById("root");
ReactDOM.render(<KlageHome />, rootElement);