Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获的TypeError:对象(…)不是函数_Javascript_Preact - Fatal编程技术网

Javascript 未捕获的TypeError:对象(…)不是函数

Javascript 未捕获的TypeError:对象(…)不是函数,javascript,preact,Javascript,Preact,我对Preact非常陌生,当我想在Preact中使用钩子时,我得到一个错误: Uncaught TypeError: Object(...) is not a function 我也不知道该怎么办,网上有一些关于预演的文章 这是我的密码 import './style'; import { useState } from 'preact'; function App() { const [value, setValue] = useState(0); const increment

我对Preact非常陌生,当我想在Preact中使用钩子时,我得到一个错误:

Uncaught TypeError: Object(...) is not a function
我也不知道该怎么办,网上有一些关于预演的文章

这是我的密码

import './style';
import { useState } from 'preact';

function App() {
  const [value, setValue] = useState(0);
  const increment = useCallback(() => setValue(value + 1), [value]);

  return (
    <div>
      Counter: {value}
      <button onClick={increment}>Increment</button>
    </div>
  );
}

export default App
import./style';
从'preact'导入{useState};
函数App(){
const[value,setValue]=useState(0);
const increment=useCallback(()=>setValue(value+1),[value]);
返回(
计数器:{value}
增量
);
}
导出默认应用程序

导入错误。应该是:

import { useState } from 'preact/hooks';
请参见此处的文档:

import./style';
从'preact'导入{useState};
const App=props=>{
const[value,setValue]=useState(0);
const increment=useCallback(()=>setValue(value+1),[value]);
返回(
计数器:{value}
增量
);
};
导出默认应用程序;

我想你忘了导入useCallback钩子。它应该是从'preact/hooks'导入{useState,useCallback};这些答案解决了你的问题吗?没有,是它自己解决的
import './style';
import { useState } from 'preact';

const App = props => {
  const [value, setValue] = useState(0);
  const increment = useCallback(() => setValue(value + 1), [value]);

  return (
    <div>
      Counter: {value}
      <button onClick={increment}>Increment</button>
    </div>
  );
};

export default App;