我想知道 react 事件之间有什么区别:onFocus
和 onFocusCapture
.我在 react 的文档页面上找不到合适的答案。
<OutlinedInput
label="price from"
onFocus={handlePriceFocus}
/>
<OutlinedInput
label="price to"
onFocusCapture={handlePriceFocus}
/>
就我而言,它似乎是 onFocus
和 onFocusCapture
执行相同的功能,因为我在使用这两个事件时没有注意到任何区别。
最佳答案
这就是 React 在他们的文档中所说的:
"The event handlers below are triggered by an event in the bubbling phase. To register an event handler for the capture phase, append Capture to the event name; for example, instead of using onClick, you would use onClickCapture to handle the click event in the capture phase." reactjs.org/docs/events
所以,我觉得这点没什么好说的了。我的理解就像没有“捕获”代码在事件之后执行,而“捕获”代码在事件之前执行。
关于javascript - React onFocus 和 onFocusCapture 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66798706/