Skip to content

Commit 4ac8fd7

Browse files
authored
Update 2020-08-10-react-v17-rc.md (reactjs#3190)
Use modern syntax for a capture-phase event listener example: flags object rather than raw boolean
1 parent 7d7c3c5 commit 4ac8fd7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

content/blog/2020-08-10-react-v17-rc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ document.addEventListener('click', function() {
9494
});
9595
```
9696

97-
You can fix code like this by converting your listener to use the [capture phase](https://javascript.info/bubbling-and-capturing#capturing). To do this, you can pass `true` as the third argument to `document.addEventListener`:
97+
You can fix code like this by converting your listener to use the [capture phase](https://javascript.info/bubbling-and-capturing#capturing). To do this, you can pass `{ capture: true }` as the third argument to `document.addEventListener`:
9898

9999
```js
100100
document.addEventListener('click', function() {
101101
// Now this event handler uses the capture phase,
102102
// so it receives *all* click events below!
103-
}, true);
103+
}, { capture: true });
104104
```
105105

106106
Note how this strategy is more resilient overall -- for example, it will probably fix existing bugs in your code that happen when `e.stopPropagation()` is called outside of a React event handler. In other words, **event propagation in React 17 works closer to the regular DOM**.

0 commit comments

Comments
 (0)