<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Displaying React based widget from Expand Widget in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/displaying-react-based-widget-from-expand-widget/m-p/1314412#M81838</link>
    <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/555184"&gt;@NikMartin&lt;/a&gt;&amp;nbsp; this isn't an issue with the ArcGIS JS SDK. It's a problem with the React component coding, it looks like the component (as an HTMLElement) has not been imported into the app correctly. Here is a conceptual example: &lt;A href="https://developers.arcgis.com/javascript/latest/custom-ui/#import-the-component-into-your-application" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/custom-ui/#import-the-component-into-your-application&lt;/A&gt;. Without a reproducible sample via a github repo or Stackblitz we can't tell for certain. You'll need to provide a link to one if you are still stuck.&lt;/P&gt;&lt;P&gt;Also note, React recommends not using Class components: &lt;A href="https://react.dev/reference/react/Component" target="_blank"&gt;https://react.dev/reference/react/Component&lt;/A&gt;. They recommend migrating to functions, which is the pattern we demonstrate in the &lt;A href="https://github.com/Esri/jsapi-resources/tree/main/esm-samples/jsapi-custom-ui" target="_self"&gt;jsapi-custom-ui&lt;/A&gt; sample.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Aug 2023 00:55:36 GMT</pubDate>
    <dc:creator>AndyGup</dc:creator>
    <dc:date>2023-08-02T00:55:36Z</dc:date>
    <item>
      <title>Displaying React based widget from Expand Widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/displaying-react-based-widget-from-expand-widget/m-p/1314275#M81831</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am implementing a custom widget in Typescript+React that has its own UI, but when I try to display the widget in an expand widget, I just get [Object Object] when the Expand widget expands to display my widget.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function App() {
  const [viewState, setViewState] = useState(null);

  const mapDiv = useRef(null);
  const webMap = useRef(null);
  const mapView = useRef(null);
  const printWidget = useRef(null);
  const printExpand = useRef(null);
 
  const config = useRef({
    printServiceVersion: 10.6,
    filename: "Print",
    widgetMode: true,
   
  });
 
  useEffect(() =&amp;gt; {
    if (mapDiv.current) {
      esriConfig.portalUrl = portalURL;
      webMap.current = new WebMap({
        portalItem: {
          id: "7a7350f559734d9197dca846de069342",
        },
      });
      mapView.current = new MapView({
        container: mapDiv.current,
        map: webMap.current
      });

      printWidget.current = new PatrickPrint({ map: webMap.current, view: mapView.current, config: config.current });

      printExpand.current = new Expand({
        expandIconClass: "esri-widget--button esri-widget print-icon",
        expandTooltip: "Print",
        view: mapView.current,
        content: printWidget.current,
        expanded: false
      });
      mapView.current.ui.add(printExpand.current, "top-right");
      webMap.current.when(() =&amp;gt; {
        setViewState({ view: mapView.current })
      })
    }
  }, [mapDiv]);

  return (
    &amp;lt;div className="App" ref={mapDiv}&amp;gt;&amp;lt;/div&amp;gt;
  );
}

export default App;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In my widget, I have stripped it down to the bare code from the /jsapi-custom-ui example project:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;export default class PatrickPrint extends React.Component&amp;lt;PatrickPrintParams, State&amp;gt; {

render() {
     return (&amp;lt;div&amp;gt;Hello&amp;lt;/div&amp;gt;);
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When it loads, I get this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Screenshot 2023-08-01 144613.png" style="width: 170px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/77014i9701DF839BD0DE03/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2023-08-01 144613.png" alt="Screenshot 2023-08-01 144613.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I'm expecting a simple div with 'Hello' to be rendered.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 20:19:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/displaying-react-based-widget-from-expand-widget/m-p/1314275#M81831</guid>
      <dc:creator>NikMartin</dc:creator>
      <dc:date>2023-08-01T20:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying React based widget from Expand Widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/displaying-react-based-widget-from-expand-widget/m-p/1314405#M81836</link>
      <description>&lt;P&gt;The Expand widget can't display React vdom directly. You'll probably want to look at portals for React.&lt;/P&gt;&lt;P&gt;&lt;A href="https://react.dev/reference/react-dom/createPortal" target="_blank"&gt;https://react.dev/reference/react-dom/createPortal&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You can place a dom element in the expand widget that is used as the element a React component is displayed.&lt;/P&gt;&lt;P&gt;Here is a blog post showing how it would work for Popup, similar to how it would work in Expand.&lt;/P&gt;&lt;P&gt;&lt;A href="https://odoe.net/blog/popup-react-portals" target="_blank"&gt;https://odoe.net/blog/popup-react-portals&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 00:22:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/displaying-react-based-widget-from-expand-widget/m-p/1314405#M81836</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2023-08-02T00:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying React based widget from Expand Widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/displaying-react-based-widget-from-expand-widget/m-p/1314412#M81838</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/555184"&gt;@NikMartin&lt;/a&gt;&amp;nbsp; this isn't an issue with the ArcGIS JS SDK. It's a problem with the React component coding, it looks like the component (as an HTMLElement) has not been imported into the app correctly. Here is a conceptual example: &lt;A href="https://developers.arcgis.com/javascript/latest/custom-ui/#import-the-component-into-your-application" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/custom-ui/#import-the-component-into-your-application&lt;/A&gt;. Without a reproducible sample via a github repo or Stackblitz we can't tell for certain. You'll need to provide a link to one if you are still stuck.&lt;/P&gt;&lt;P&gt;Also note, React recommends not using Class components: &lt;A href="https://react.dev/reference/react/Component" target="_blank"&gt;https://react.dev/reference/react/Component&lt;/A&gt;. They recommend migrating to functions, which is the pattern we demonstrate in the &lt;A href="https://github.com/Esri/jsapi-resources/tree/main/esm-samples/jsapi-custom-ui" target="_self"&gt;jsapi-custom-ui&lt;/A&gt; sample.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 00:55:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/displaying-react-based-widget-from-expand-widget/m-p/1314412#M81838</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2023-08-02T00:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying React based widget from Expand Widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/displaying-react-based-widget-from-expand-widget/m-p/1315036#M81851</link>
      <description>&lt;P&gt;Thank you Andy, I was able to get it working with a few more Google searches, by injected a div into the DOM, like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function App() {
  const targetContainer = document.createElement('div');
  const root = createRoot(targetContainer);
  const [viewState, setViewState] = useState(null);

  const mapDiv = useRef(null);
  const webMap = useRef(null);
  const mapView = useRef(null);
  const printExpand = useRef(null);
  

  useEffect(() =&amp;gt; {
    if (mapDiv.current) {
      webMap.current = new WebMap({
        portalItem: {
          id: "7a7350f559734d9197dca846de069342",
        },
      });
      mapView.current = new MapView({
        container: mapDiv.current,
        map: webMap.current
      });

      printExpand.current = new Expand({
        expandIconClass: "esri-widget--button esri-widget print-icon",
        expandTooltip: "Print",
        view: mapView.current,
        content: targetContainer,
        expanded: false
      });
      mapView.current.ui.add(printExpand.current, "top-right");
      webMap.current.when(() =&amp;gt; {
        setViewState({ view: mapView.current })
      })
      root.render(
        &amp;lt;PatrickPrint map={webMap.current} view={mapView.current} config={config.current}/&amp;gt;
    );

    }
  }, [mapDiv]);

  return (
    &amp;lt;div className="App" ref={mapDiv}&amp;gt;&amp;lt;/div&amp;gt;
  );
}
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not as elegant as I hoped, but seems to be working fine.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 14:01:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/displaying-react-based-widget-from-expand-widget/m-p/1315036#M81851</guid>
      <dc:creator>NikMartin</dc:creator>
      <dc:date>2023-08-03T14:01:00Z</dc:date>
    </item>
  </channel>
</rss>

