rum*_*mon 2 javascript reactjs react-hooks
有什么区别
onChange={({ target: { value } }) => setInsertedTitle(value)}
Run Code Online (Sandbox Code Playgroud)
和
onChange={setInsertedTitle}
Run Code Online (Sandbox Code Playgroud)
什么时候应该使用其中一种或另一种?
使用onChange={({ target: { value } }) => setInsertedTitle(value)}您将当前目标值作为参数传递。
这是因为 onChange 生成一个Event,并且您通过 event.target.value 访问该值...
event: {
target: {
value: "string"
}
}
Run Code Online (Sandbox Code Playgroud)
另一方面,当您使用 onChange={setInsertedTitle} 中的函数时,它会接收事件。
您可以在这里看到它:https ://codesandbox.io/s/compassionate-fast-krrib?file=/src/App.js
| 归档时间: |
|
| 查看次数: |
4170 次 |
| 最近记录: |