Skip to content

Instantly share code, notes, and snippets.

@brunos3d
Created May 23, 2023 15:27
Show Gist options
  • Save brunos3d/1dfa176d39d2af5de75e8926478ae087 to your computer and use it in GitHub Desktop.
Save brunos3d/1dfa176d39d2af5de75e8926478ae087 to your computer and use it in GitHub Desktop.
const hrefMonkeyPatch = () => {
const originalCreateElement = React.createElement;
React.createElement = function createElement () {
const args = Array.prototype.slice.call(arguments);
if (!args[1]) {
args[1] = {};
}
const element = args[0];
const props = args[1];
if (props?.['data-no-patch']) {
return originalCreateElement.apply(React, args);
}
if (element === 'a' && props.href) {
props.href += "?TESTE=TESTE";
}
return originalCreateElement.apply(React, args);
};
return () => {
React.createElement = originalCreateElement;
};
};
export default hrefMonkeyPatch;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment