亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Uncaught TypeError: Object (...) is not a function

Uncaught TypeError: Object (...) is not a function

30秒到達戰場 2022-01-20 20:45:12
我對 Preact 很陌生,當我想在 Preact 中使用鉤子時,我收到一個錯誤:Uncaught TypeError: Object(...) is not a function而且我不知道該怎么做,網上有一些關于 Preact 的文章這是我的代碼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
查看完整描述

2 回答

?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

你導入錯了。應該:

import { useState } from 'preact/hooks';

請參閱此處的文檔:https ://preactjs.com/guide/v10/hooks/#usestate


查看完整回答
反對 回復 2022-01-20
?
慕尼黑5688855

TA貢獻1848條經驗 獲得超2個贊

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;


查看完整回答
反對 回復 2022-01-20
  • 2 回答
  • 0 關注
  • 1724 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號