我正在尝试学习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 iterable
App
src/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)
import React, { useState } from "react"
这是正确的导入声明
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句