{body}
### Complete React app example with HTML, index.js, and App.js Source: https://react.dev/reference/react-dom/client/createRoot Full working example showing the HTML entry point with a root div, the index.js file that initializes React, and the App.js component with a simple counter. The index.js file is marked as active in the interactive example. ```html
{details.title}
{details.description}
> ); } ``` ```js import { useId, useState, use, useDeferredValue, ViewTransition } from "react";import { Video } from "./Videos";import Layout from "./Layout";import { fetchVideos } from "./data";import { IconSearch } from "./Icons"; function SearchList({searchText, videos}) { // Activate with useDeferredValue ("when") const deferredSearchText = useDeferredValue(searchText); const filteredVideos = filterVideos(videos, deferredSearchText); return (
);
}
```
```javascript
import Gallery from './Gallery.js';
import { createRoot } from 'react-dom/client';
const root = createRoot(document.getElementById('root'))
root.render(You clicked {count} times
{sculpture.description}
> ); } ``` -------------------------------- ### Full example: Integrate React Portal with a Leaflet map widget popup Source: https://react.dev/reference/react-dom/createPortal This comprehensive example showcases the integration of React Portals with a third-party Leaflet map widget. It demonstrates how to initialize the map, create a popup, and then render a React component directly into that popup's DOM node using createPortal, providing a complete, runnable solution for external DOM node integration. ```json { "dependencies": { "leaflet": "1.9.1", "react": "latest", "react-dom": "latest", "react-scripts": "latest", "remarkable": "2.0.1" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } } ``` ```javascript import { useRef, useEffect, useState } from 'react'; import { createPortal } from 'react-dom'; import { createMapWidget, addPopupToMapWidget } from './map-widget.js'; export default function Map() { const containerRef = useRef(null); const mapRef = useRef(null); const [popupContainer, setPopupContainer] = useState(null); useEffect(() => { if (mapRef.current === null) { const map = createMapWidget(containerRef.current); mapRef.current = map; const popupDiv = addPopupToMapWidget(map); setPopupContainer(popupDiv); } }, []); return (Hello from React!
, popupContainer )}{body}