Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lemanschik/75b895ffcd77789aee5956bcf2e9ee4c to your computer and use it in GitHub Desktop.
Save lemanschik/75b895ffcd77789aee5956bcf2e9ee4c to your computer and use it in GitHub Desktop.
React 19 Custom Elements

If onClick the component fires first if onclick react fires first the default behavior is that all serialiseable props get attributes and properties so be aware that you could overwrite some default HTMLElement properties with intend or without :)

customElements.define('super-click', class SuperClick extends HTMLElement {
  connectedCallback() {
    alert('Comp');
    this.onclick = () => {
      alert('clicked');
    };
    //this.innerHTML = `Clock me`
  }
});
export default function Button() {
  function handleClick() {
    alert('You clicked me!');
  }
     alert('render');
  return (<>
    <p>1</p>
    <super-click N="me" className="heroo" onClick={handleClick}>
      Click me
    </super-click>
    </>
  );
}


@lemanschik
Copy link
Author

in style properties the order does matter as React uses a for i loop.

    <super-click N="me"  style={{marginRight:  1 + 'em', cssText: "border:solid 10px; color:green;", color: "red",  border: "solid 5px",   }} className="heroo" onClick={handleClick}>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment