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

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

useState 反應鉤子

useState 反應鉤子

開心每一天1111 2023-06-15 17:12:44
我正在嘗試學習 React 鉤子。但我無法讓第一個工作。這是一個非?;镜膽贸绦颍绻也荒茏?useState 工作,我就無法前進。import React, { useState } from "react-dom"import './App.css';function App(props) {  const [click, setClick] = useState(0);  const handleChange = e => {     console.log(e.target.value)  }  const handleClick = e => {     console.log(e.target)  }  return (    <div className="App">      Value<input type="text" onChange={ handleChange }/>      <select>        <option>F to C degrees</option>        <option>C to F degrees</option>      </select>      <button onClick={handleClick}>Go</button>    </div>  );}export default App;那是我的應用程序,只是為了讓您知道我所有的反應都是相同的版本  "dependencies": {    "@testing-library/jest-dom": "^5.11.4",    "@testing-library/react": "^11.1.0",    "@testing-library/user-event": "^12.1.10",    "react": "17.0.1",    "react-dom": "17.0.1",    "react-scripts": "4.0.1",    "react-test-renderer": "17.0.1",    "web-vitals": "^0.2.4"  },我得到的錯誤是:TypeError: Object is not a function or its return value is not iterableAppsrc/App.js:5  2 | import './App.css';  3 |   4 | function App(props) {> 5 |   const [click, setClick] = useState(0);  6 |   7 |   const handleChange = e => {   8 |     console.log(e.target.value)
查看完整描述

3 回答

?
猛跑小豬

TA貢獻1858條經驗 獲得超8個贊

import React, { useState } from "react"

這是正確的導入語句


查看完整回答
反對 回復 2023-06-15
?
MMTTMM

TA貢獻1869條經驗 獲得超4個贊

我認為react-dom沒有useState,所以將文件的頂部更改為:


import React, { useState } from "react"

import './App.css';


function App(props) {

  const [click, setClick] = useState(0);


  const handleChange = e => { 

    console.log(e.target.value)

  }


  const handleClick = e => { 

    console.log(e.target)

  }


  return (

    <div className="App">

      Value<input type="text" onChange={ handleChange }/>

      <select>

        <option>F to C degrees</option>

        <option>C to F degrees</option>

      </select>

      <button onClick={handleClick}>Go</button>

    </div>

  );

}


export default App;


查看完整回答
反對 回復 2023-06-15
?
烙印99

TA貢獻1829條經驗 獲得超13個贊

import React from "react"


const App = (props)=>{

const [click, setClick] = useState(0);


const handleChange = e => { 

console.log(e.target.value)


 }


 const handleClick = e => { 

 console.log(e.target)

  

}


return (

<div className="App">

  Value<input type="text" onChange={ handleChange }/>

  <select>

    <option>F to C degrees</option>

    <option>C to F degrees</option>

  </select>

  <button onClick={handleClick}>Go</button>

</div>

  );

  } 


 export default App;


查看完整回答
反對 回復 2023-06-15
  • 3 回答
  • 0 關注
  • 164 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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