Not working with React event handlers #229
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi,
I'm using pjax along with some React components. I'm trying to disable some links programmatically, depending on the current state of the component, by using
onClick/onClickCaptureevent handlers along with somestopPropagationandpreventDefaultmethods. But this is not working as expected, as the links are still enabled.Here is a small example to reproduce:
Tested with the latest versions of Firefox and Chrome.
From what I understand, this is because React's
SyntheticEventsare always processed after native events, which are the one used by Pjax.A quick test shows indeed that the
isDefaultPreventedfunction returnsfalseafter theonClickhandler is being called, but this is already too late.The solution is... don't mix native events with React events, which means using a React-compatible version of pjax. Unfortunately for me, this won't be possible as my app is not a full-React app, but just isolated components here and there, but this is definitely not pjax's fault.
Anyway, if someone still manages to find a workaround for this particular case, I'd be happy to see it!