-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
第 17 题:React 事件绑定原理 #23
Comments
1)事件注册
2)事件存储
{
onClick:{
nodeid1:()=>{...}
nodeid2:()=>{...}
},
onChange:{
nodeid3:()=>{...}
nodeid4:()=>{...}
}
} 3)事件触发执行
代码示例 <div onClick={this.parentClick} ref={ref => this.parent = ref}>
<div onClick={this.childClick} ref={ref => this.child = ref}>
test
</div>
</div>
4)合成事件
5)总流程 |
很详细 |
如果遇到了事件冒泡的节点,是不是render的时候就不会更新事件冒泡以上的父组件,还是说更新组件更props的变更有关 |
另外冒泡到 document 上的事件也不是原生浏览器事件,而是 React 自己实现的合成事件(SyntheticEvent)。因此我们如果不想要事件冒泡的话,调用 event.stopPropagation 是无效的,而应该调用 event.preventDefault。 这里是不是有问题的? https://codesandbox.io/s/withered-snow-3dq39?file=/src/App.js 在这个例子中调用了event.preventDefault,但并未阻止冒泡 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
欢迎在下方发表您的优质见解
The text was updated successfully, but these errors were encountered: