<?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: Basemaps are duplicated in BasemapGallery widget in ReactJS app in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/basemaps-are-duplicated-in-basemapgallery-widget/m-p/1524644#M85441</link>
    <description>&lt;P&gt;Thanks for taking a look.&amp;nbsp; Unfortunately, the code is private, so I can't share the repo.&amp;nbsp; I will look into creating a stackblitz if I'm still stuck after trying your suggestions.&amp;nbsp; I just ran a build and it is still showing the basemaps repeated, so I don't think HMR is the culprit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bradMaps_0-1724181018350.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/112982iD962830F46E33F8A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="bradMaps_0-1724181018350.png" alt="bradMaps_0-1724181018350.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Aug 2024 19:11:05 GMT</pubDate>
    <dc:creator>bradMaps</dc:creator>
    <dc:date>2024-08-20T19:11:05Z</dc:date>
    <item>
      <title>Basemaps are duplicated in BasemapGallery widget in ReactJS app</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/basemaps-are-duplicated-in-basemapgallery-widget/m-p/1522530#M85382</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a React 17 app utilizing 4.21 of the JS Maps SDK.&amp;nbsp; I am able to add the BasemapGallery widget with two basemaps, but the basemap tiles are duplicated 14 times.&amp;nbsp; Is there a hook I should be using to prevent the duplication?&lt;/P&gt;&lt;P&gt;Also, how can I force the gallery to display as 3 horizontal tiles per row, instead of just vertically?&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const BasemapGroup = ({
  label,
}: {
  label: string;
  children?: React.ReactNode;
}) =&amp;gt; {
  const mapComponents = useContext(MapContext);
  const [open, setOpen] = useState(false);
  const classes = useStyles();

  const basemapGallery = new BasemapGallery({
    view: mapComponents.view,
    source: [Basemap.fromId("hybrid"), Basemap.fromId("gray")],
  });
  return (
    &amp;lt;Box mb={5} className={classes.layerGroupContainer}&amp;gt;
      &amp;lt;MetricLabelLight
        style={{ color: palette.blue, cursor: "pointer" }}
        onClick={() =&amp;gt; {
          setOpen(!open);
        }}
      &amp;gt;
        {label}
      &amp;lt;/MetricLabelLight&amp;gt;
      &amp;lt;Collapse in={true} timeout={500}&amp;gt;
        &amp;lt;div
          ref={(element) =&amp;gt; element &amp;amp;&amp;amp; (basemapGallery.container = element)}
        &amp;gt;&amp;lt;/div&amp;gt;
      &amp;lt;/Collapse&amp;gt;
    &amp;lt;/Box&amp;gt;
  );
};

...

&amp;lt;BasemapGroup label="Basemaps" key="Basemaps"&amp;gt;&amp;lt;/BasemapGroup&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 20:08:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/basemaps-are-duplicated-in-basemapgallery-widget/m-p/1522530#M85382</guid>
      <dc:creator>bradMaps</dc:creator>
      <dc:date>2024-08-15T20:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: Basemaps are duplicated in BasemapGallery widget in ReactJS app</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/basemaps-are-duplicated-in-basemapgallery-widget/m-p/1523929#M85408</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/7384"&gt;@ReneRubalcava&lt;/a&gt;&amp;nbsp;curious if you have any ideas for troubleshooting.&amp;nbsp; Thanks!!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 17:44:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/basemaps-are-duplicated-in-basemapgallery-widget/m-p/1523929#M85408</guid>
      <dc:creator>bradMaps</dc:creator>
      <dc:date>2024-08-19T17:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: Basemaps are duplicated in BasemapGallery widget in ReactJS app</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/basemaps-are-duplicated-in-basemapgallery-widget/m-p/1524011#M85409</link>
      <description>&lt;P&gt;Tough to tell from snippet, if you have a git repo or stackblitz, might be able to tell.&lt;/P&gt;&lt;P&gt;You probably don't want to assign the BasemapGallery container directly, do it in a useEffect with a useRef with some guards against nulls and stuff.&lt;/P&gt;&lt;P&gt;Does this happen in dev mode and prod? HMR can do this sometimes.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 20:01:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/basemaps-are-duplicated-in-basemapgallery-widget/m-p/1524011#M85409</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2024-08-19T20:01:35Z</dc:date>
    </item>
    <item>
      <title>Re: Basemaps are duplicated in BasemapGallery widget in ReactJS app</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/basemaps-are-duplicated-in-basemapgallery-widget/m-p/1524644#M85441</link>
      <description>&lt;P&gt;Thanks for taking a look.&amp;nbsp; Unfortunately, the code is private, so I can't share the repo.&amp;nbsp; I will look into creating a stackblitz if I'm still stuck after trying your suggestions.&amp;nbsp; I just ran a build and it is still showing the basemaps repeated, so I don't think HMR is the culprit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bradMaps_0-1724181018350.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/112982iD962830F46E33F8A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="bradMaps_0-1724181018350.png" alt="bradMaps_0-1724181018350.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2024 19:11:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/basemaps-are-duplicated-in-basemapgallery-widget/m-p/1524644#M85441</guid>
      <dc:creator>bradMaps</dc:creator>
      <dc:date>2024-08-20T19:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Basemaps are duplicated in BasemapGallery widget in ReactJS app</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/basemaps-are-duplicated-in-basemapgallery-widget/m-p/1524655#M85443</link>
      <description>&lt;P&gt;useEffect/useRef fixed it!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For anyone interested, here's the new code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const BasemapGroup = ({
  label,
}: {
  label: string;
  children?: React.ReactNode;
}) =&amp;gt; {
  const mapComponents = useContext(MapContext);
  const [open, setOpen] = useState(false);
  const classes = useStyles();

  const basemapGalleryRef = useRef&amp;lt;BasemapGallery | null&amp;gt;(null);

  useEffect(() =&amp;gt; {
    mapComponents.view.when(() =&amp;gt; {
      basemapGalleryRef.current = new BasemapGallery({
        view: mapComponents.view,
        source: [Basemap.fromId("hybrid"), Basemap.fromId("gray")],
      });
    });
  }, [mapComponents.view]);

  const basemapGallery = basemapGalleryRef.current;

  return (
    &amp;lt;Box mb={5} className={classes.layerGroupContainer}&amp;gt;
      &amp;lt;MetricLabelLight
        style={{ color: palette.blue, cursor: "pointer" }}
        onClick={() =&amp;gt; {
          setOpen(!open);
        }}
      &amp;gt;
        {label}
      &amp;lt;/MetricLabelLight&amp;gt;
      &amp;lt;Collapse in={true} timeout={500}&amp;gt;
        &amp;lt;div
          ref={(element) =&amp;gt;
            element &amp;amp;&amp;amp; basemapGallery &amp;amp;&amp;amp; (basemapGallery.container = element)
          }
        &amp;gt;&amp;lt;/div&amp;gt;
      &amp;lt;/Collapse&amp;gt;
    &amp;lt;/Box&amp;gt;
  );
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any tips on forcing&amp;nbsp;&lt;SPAN&gt;the gallery to display as 3 horizontal tiles per row, instead of just vertically?&amp;nbsp; It seems that if the width is &amp;gt; 450px, it should show as 3 tiles per row.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2024 19:26:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/basemaps-are-duplicated-in-basemapgallery-widget/m-p/1524655#M85443</guid>
      <dc:creator>bradMaps</dc:creator>
      <dc:date>2024-08-20T19:26:30Z</dc:date>
    </item>
  </channel>
</rss>

