const useState = React.useState; function getComponentProps(node) { const attributeNames = node.getAttributeNames(); const props = {}; for (const attributeName of attributeNames) { if (attributeName.startsWith("data-")) { const propName = attributeName.slice(5); props[propName] = node.getAttribute(attributeName); } } return props; } function mountComponent(querySelector, Component) { const containers = document.querySelectorAll(querySelector); for (const container of containers) { const props = getComponentProps(container); const root = ReactDOM.createRoot(container); root.render(); } } // LikeButtonWithTitle Component function LikeButtonWithTitle({ title, margin, padding }) { const [likeCount, setLikeCount] = useState(100500); return ( ); } mountComponent(".LikeButtonWithTitle", LikeButtonWithTitle); // ReactGreeter component function ReactGreeter() { const [name, setName] = useState(""); const onSubmit = (event) => { event.preventDefault(); alert(`Hello, ${name}!`); }; return (
setName(event.target.value)} />
); } mountComponent(".ReactGreeter", ReactGreeter);