Feature Request: Event Modifiers support

This issue has been created since 2022-09-08.

I'm moving from Vue to React recently, and one of the few practical features I miss is native Event Modifiers support.

Vue supports several types of native events that make development very convenient. The ones I miss the most are:

  • .stop: same as e.stopPropagation().
  • .prevent: same as e.preventDefault();


  • Allows the function defined in the handle to perform its main function without worrying about the event flow;
  • Facilitates the reuse of callbacks that control the flow differently, but achieve the same result;
function handleClick(e) {

function handleClickWithStop(e) {
<div onClick={handleClickWithStop}>must stop</div>
<div onClick={handleClick}>must continue</div>


function handleClick(e) {
<div onClick.stop={handleClick}>must stop</div>
<div onClick={handleClick}>must continue</div>


The only thing I can think of being "against" is that it might increase the cost of converting from JSX to native JS. Although I think this only happens during the build process. Right?

During the conversion process, events will need to identify the .indexOf('.') and then apply the necessary wrappers:

    { onClick: function (e) {
      } }
markerikson wrote this answer on 2022-09-10

This is really a request for a change to the JSX syntax definition and compilers like Babel, TypeScript, and ESBuild, not React itself.

Given that, this is highly unlikely to ever happen, for a few reasons:

  • JSX is intended to be a fairly straightforward transformation into plain JS function calls, and this adds additional complexity
  • The JSX spec has been frozen for years, and even relatively simple proposed changes haven't happened
  • This would require coordination across a massive ecosystem of tools
rentalhost wrote this answer on 2022-09-10

@markerikson that makes complete sense. I really thought that React performed some kind of transformation on the processed JSX and had greater control over it (maybe it is possible from the React side, but in fact, ideally it would be part of the JSX if that was the case).

markerikson wrote this answer on 2022-09-10

Yeah, strictly speaking the JSX transform isn't part of "React" the software library at all. JSX was invented for use with React, but many tools now implement that syntax (even Vue!), and the output is just the function calls to React.createElement() or the equivalent for other libraries.

If you want to get a sense of some other proposed changes to the JSX spec (none of which have become reality), see the discussions in this thread:

gaearon wrote this answer on 2022-09-11

I’m not sure the biggest problem here is with JSX being frozen. I think my main objection would be that it “feels” like specifying information in a wrong place.

In this proposal whether to stop propagation or not seems to be specified as part of the event key. So it’s as if we’re saying that onClick.stop is a separate event from onClick. What happens if you specify both? Do both run or does one override the other? Does it error?

What if you do <div onClick {…props}> and props contains an object with the key onClick.stop because the parent passed it to your custom component? Do they clash? Or does this prop only work on built-ins? If it only works on built-ins, how are you supposed to refactor the code when you wrap a component? How do you destructure the prop in your component given . is not a valid part of the identifier?

What if you want to render a third-party component that only takes onClick but you want it to stop propagation. Do you do it manually? Does it have to support both versions explicitly? Does the .stop syntax actually rewrite the function that you pass to it? What if you define this function separately like onClick.stop={handleClick}? Does this attach some metadata to the function itself? Does this wrap it into a special object and make it opaque?

Is this syntax only for event handlers? What about other functions being passed down?

I think there could be something to explore with event handler metadata. Like passive events (which we don’t support at all), or bubble/capture (which we support via Capture suffix) are two real dimensions. Declarative prevent/stop could maybe be a thing too. But I’d need to understand the proposed design a lot more. So far it’s not clear to me how this can work, and I’m not familiar with how it works with Vue. In particular we care a lot about code using custom components looking good and working well, so it needs to be a first-class consideration. We can’t have built-ins with more “conveniences” than custom components.

rentalhost wrote this answer on 2022-09-12

@gaearon your question is very interesting. I'll answer based on what vue does in this case:

When an element has only one @click="handleClick", for example, we get something like:

_createElementVNode("div", {
    onClick: _cache[0] || (_cache[0] = (...args)=>(_ctx.handleClick && _ctx.handleClick(...args)))

However, if we have a definition @click and @click.stop at the same time, we will have:

_createElementVNode("div", {
    onClick: [
        _cache[0] || (_cache[0] = (...args)=>(_ctx.handleClick && _ctx.handleClick(...args))), 
        _cache[1] || (_cache[1] = _withModifiers((...args)=>(_ctx.handleClick && _ctx.handleClick(...args)), ["stop"]))

Which indicates that vue accepts this condition well, transforming .onClick into an array of events, instead of a direct event (like the first case).

Not only that, but @click (and events in general) allows the use of an array containing multiple definitions for methods, so the same event can perform different functions without a wrapper: @click="[ handleClick($event), handleClickTwo($event) ]"

_createElementVNode("div", {
    onClick: _cache[0] || (_cache[0] = $event=>([$setup.handleClick($event), $setup.handleClickTwo($event)]))

As for the example of ...props, the code @click="handleClick" v-bind:onClick="handleClickTwo" is converted to:

_createElementVNode("div", {
    onClick: [$setup.handleClick, $setup.handleClickTwo]
}, "teste")

As for third-party code, you can even define both @click and @click.stop with independent supports, but at this point it would be overkill. If the code user needs a stop beyond what is developed by the third party code, then he will have to do it directly by the JS.

In vue, events are declared explicitly using @. Which means that @something is necessarily an event, and stop and prevent support are applicable exclusively in these cases. In addition, there is other support for specific events such as @keydown.enter, @keydown.space etc. I don't think anything at this level can be done in React.

More Details About Repo
Owner Name facebook
Repo Name react
Full Name facebook/react
Language JavaScript
Created Date 2013-05-24
Updated Date 2022-09-26
Star Count 195293
Watcher Count 6655
Fork Count 40426
Issue Count 1113


Issue Title Created Date Comment Count Updated Date
[bug] Some iOS icons are wrong 1 2022-09-02 2022-09-25
Openpyn Autostart on Debian 2 2021-11-12 2022-09-17
[movement-controls] touch-controls not working when camera/rig is added dynamically 3 2020-03-03 2022-09-10
indexing GRCh38 failed 1 2021-06-29 2022-08-13
Coordinate 'Transformation' between poses 8 2019-10-06 2022-08-21
write_dta fails with "variable_value_labels type must be boolean or be 1 or 0" if only NaNs and missing_user_values in series 2 2021-12-16 2022-09-04
Ensure org-cite cache gets updated 1 2022-02-09 2022-08-11
how to get attention layer? 0 2022-03-14 2022-09-24
MaintenaceType property mispelled 0 2022-05-19 2022-08-22
Pset_ConstructionOccurance misspelled 0 2022-05-19 2022-08-22
Create wrapper types for arrays 0 2021-08-18 2021-12-16
unable to install 2 2021-10-29 2022-01-16
Custom Template does not work 2 2022-05-31 2022-08-26
Add support for HTMLHint diagnostics 3 2021-10-30 2022-08-20
auto模式数据库BROADCAST表创建失败 3 2022-08-03 2022-09-25
Ubuntu Budgie 22.04 LTS (Jammy Jellyfish) 35 2022-03-27 2022-09-26
Sample data install doesn't work on the Automated Setup 5 2021-05-20 2022-07-29
Community Roadmap 0 2021-05-07 2021-11-22
Profils les plus actifs 0 2021-09-22 2022-09-17
Improve "OSA UCS" to "CIE XYZ" conversion. 1 2021-01-20 2022-09-23
issue: [delayError] error not shown when switching to a field with a different rule 5 2022-06-15 2022-09-19
zh_docs/docs/source/use_op/cluster_status.rst 1 2020-06-10 2021-12-23
Flux getting into hang state on any java.lang.Error or its subclasses 1 2022-05-08 2022-09-23
Move abstract scalar functions integration tests from postgresql-virtual-schema 0 2021-03-03 2022-09-19
`spree:install` fails when `spree_auth_devise` is not installed 2 2022-06-19 2022-08-22
HA Entity state not updating 10 2021-05-15 2022-08-30
4.0.2 introduced a change in Numeric parsing 1 2021-11-18 2022-09-16
Slider in subgrid causing content blocks below to be nudged down. 1 2021-09-14 2022-09-20
item category is mapped incorrectly 2 2021-01-27 2022-09-15
[Bug]: CURD >> JSONForm | Theming is not applied to Table's 'Delete' & JSONForm's 'Reset & Update' buttons 1 2022-05-25 2022-07-16
Error in module "scc_notification" 4 2021-07-21 2022-09-20
Variant tag count discrepancies 2 2022-03-10 2022-07-21
Support -Zfunction-sections 2 2022-01-25 2022-09-17
Remove Rx in zipper 0 2021-08-24 2022-01-15
create ignoreDuplicates throws an error when empty response (due to ignored duplicates) 3 2022-04-29 2022-09-18
Webcomponent splitview overlaps content area 0 2022-03-09 2022-09-25
Tekton Pipelines as Category 2 2021-08-12 2022-01-30
cargo run abort, '/usr/local/lib/libtermkey.1.dylib' (no such file) 0 2022-02-11 2022-08-01
Support the build of shared libraries via `make lib/<libname>` 4 2022-09-01 2022-09-20
lvgl:arm-ostl-linux-gnueabi-gcc compile error!fatal error: lvgl/lvgl.h: No such file or directory #include "lvgl/lvgl.h" 5 2021-08-06 2022-09-03
Generic URL Shortener 3 2022-07-01 2022-09-06
Upload worksheet to scastie 3 2021-04-13 2022-09-26
Invalid entrypoint when using aws-lambda-nodejs:14 2 2022-01-10 2022-09-18
Did I forgot something? 3 2020-01-15 2022-09-20
[BUG] MKS-GEN_L (V 1.0) pins config error for double extruder setup 5 2022-03-20 2022-09-12
Is it possible to limit the movement of child widget upto the boundaries of PhotoView.customChild? 1 2022-06-04 2022-09-15
Don't disable app analytics 4 2021-11-03 2022-09-09
Why the major version bump for v1.13? 7 2021-10-19 2022-09-15
incorporate compsys completion for zconvey commands 0 2020-08-12 2021-10-17
Remove webrtc-adapter 0 2017-09-21 2022-09-25