Dev.Lib
arrow_backBack to Blogs
LEVEL_077.6June 27, 20261 min read

Web Components interoperability

Web Platform APIs

React historically mismatched props vs attributes on custom elements — use property setters or `@lit/react` wrappers.

Summary

React historically mismatched props vs attributes on custom elements — use property setters or @lit/react wrappers. Events may need lowercase native listeners. SSR custom elements needs declarative shadow DOM or hydration libs. Test form participation and focus management.

Code example

function UserBadge({ userId }) {
  const ref = useRef(null);

  useEffect(() => {
    const el = ref.current;
    el.userId = userId; // set property, not attribute
  }, [userId]);

  return <user-badge ref={ref} />;
}

Key points

  • React historically mismatched props vs attributes on custom elements — use property setters or @lit/react wrappers.
  • Events may need lowercase native listeners.
  • SSR custom elements needs declarative shadow DOM or hydration libs.
  • Test form participation and focus management.

Further reading

Related concepts