<?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: React functional component component unmount useEffect in Experience Builder Custom Widgets</title>
    <link>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597750#M508</link>
    <description>&lt;P&gt;Unless something's gone sideways, closing the widget should trigger a re-render, which passes the updated state into the widget. Try adding an effect that has &lt;FONT face="courier new,courier"&gt;props.state&lt;/FONT&gt; as a dependency and it should only fire when that changes. If you need to explicitly look for a change instead of blind-firing on a certain state you can try something like &lt;A href="https://stackoverflow.com/a/53446665" target="_self"&gt;this SO post&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Mar 2025 19:46:01 GMT</pubDate>
    <dc:creator>DavidSolari</dc:creator>
    <dc:date>2025-03-20T19:46:01Z</dc:date>
    <item>
      <title>React functional component component unmount useEffect</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597666#M501</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have developed a custom functional component by extending the EXB 1.16. My widget allows the user to interactively apply a definition query on one of the map layers. I would like the restore the map layer to its original state when the use closes the widget.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought I would be able to use the useEffect hook as follows&lt;/P&gt;&lt;P&gt;useEffect(() =&amp;gt; {&lt;/P&gt;&lt;P&gt;console.log('component setup')&lt;/P&gt;&lt;P&gt;//any widget initialisation code&lt;/P&gt;&lt;P&gt;return () =&amp;gt; {&lt;/P&gt;&lt;P&gt;console.log('component clean up')&lt;/P&gt;&lt;P&gt;//restore layer to its original state when user closes widget&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;},[])&lt;/P&gt;&lt;P&gt;where component clean up code runs when the widget/component is closed by the user. It looks like the return function is not being called when I close the widget.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there another way I can achieve this using react functional components?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2025 17:33:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597666#M501</guid>
      <dc:creator>wadsonmakari</dc:creator>
      <dc:date>2025-03-20T17:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: React functional component component unmount useEffect</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597679#M502</link>
      <description>&lt;P&gt;ExB widgets aren't unmounted when you close the widget, they're just hidden. This is normally where I would say how to get that state but the API reference makes it incredibly difficult. You might be able to crawl through &lt;A href="https://github.com/Esri/arcgis-experience-builder-sdk-resources/tree/master/widgets/control-the-widget-state" target="_self"&gt;this example widget&lt;/A&gt; to find an answer, although I think this is more concerned with checking&amp;nbsp;&lt;EM&gt;other&lt;/EM&gt; widgets' states through the redux store.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2025 17:57:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597679#M502</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2025-03-20T17:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: React functional component component unmount useEffect</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597697#M503</link>
      <description>&lt;P&gt;Thanks for your response. I am not looking to control the state of other widgets but to just run a function that will restore the layer that the user was interacting with to its original state when the user closes/hides the widget.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a onHide event or something like that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone from ESRI comment on this?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2025 18:28:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597697#M503</guid>
      <dc:creator>wadsonmakari</dc:creator>
      <dc:date>2025-03-20T18:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: React functional component component unmount useEffect</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597700#M504</link>
      <description>&lt;P&gt;&lt;A href="https://developers.arcgis.com/experience-builder/api-reference/jimu-core/WidgetState/" target="_blank"&gt;https://developers.arcgis.com/experience-builder/api-reference/jimu-core/WidgetState/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;There is a prop built into the base widget class you should be able that will show you if the Widget is open or closed. If I remember correctly it's just props.state. (terrible name for something in React)&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2025 18:38:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597700#M504</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2025-03-20T18:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: React functional component component unmount useEffect</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597704#M505</link>
      <description>&lt;P&gt;Ah, found it, it's &lt;FONT face="courier new,courier"&gt;props.state&lt;/FONT&gt; which is a member of the &lt;A href="https://developers.arcgis.com/experience-builder/api-reference/jimu-core/WidgetState/" target="_self"&gt;&lt;FONT face="courier new,courier"&gt;WidgetState&lt;/FONT&gt;&lt;/A&gt; enum.&lt;/P&gt;&lt;P&gt;To illustrate what a mess finding this was: functional/pure widgets have no state beyond what you define, what's yoinked from a data store, or what's passed down through the props. All standard widgets take an &lt;A href="https://developers.arcgis.com/experience-builder/api-reference/jimu-core/AllWidgetProps/" target="_self"&gt;&lt;FONT face="courier new,courier"&gt;AllWidgetProps&lt;/FONT&gt;&lt;/A&gt; object, which is the sum of &lt;A href="https://developers.arcgis.com/experience-builder/api-reference/jimu-core/WidgetProps/" target="_self"&gt;&lt;FONT face="courier new,courier"&gt;WidgetProps&lt;/FONT&gt;&lt;/A&gt; and &lt;A href="https://developers.arcgis.com/experience-builder/api-reference/jimu-core/WidgetInjectedProps/" target="_self"&gt;&lt;FONT face="courier new,courier"&gt;WidgetInjectedProps&amp;lt;T&amp;gt;&lt;/FONT&gt;&lt;/A&gt; (where T is the config object?). Buried in the injected props is the &lt;A href="https://developers.arcgis.com/experience-builder/api-reference/jimu-core/RuntimeInfo/" target="_self"&gt;&lt;FONT face="courier new,courier"&gt;RuntimeInfo&lt;/FONT&gt;&lt;/A&gt; object which is where the state is stored, presumably because all of this info is coordinated by ExB and drilled into the widgets to keep a nice state tree. So yeah, easy, all you have to do is keep half of the jimu-core types in your head and you can find anything!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2025 18:45:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597704#M505</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2025-03-20T18:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: React functional component component unmount useEffect</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597708#M506</link>
      <description>&lt;P&gt;The best Experience Builder documentation is IntelliSense. Type props. and see if any of the suggestions seem useful.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2025 18:52:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597708#M506</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2025-03-20T18:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: React functional component component unmount useEffect</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597740#M507</link>
      <description>&lt;P&gt;Thanks both for your comments where do I check the props.state from? In the useEffect example above the return function is not called when the widget is closed/onhide.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2025 19:35:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597740#M507</guid>
      <dc:creator>wadsonmakari</dc:creator>
      <dc:date>2025-03-20T19:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: React functional component component unmount useEffect</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597750#M508</link>
      <description>&lt;P&gt;Unless something's gone sideways, closing the widget should trigger a re-render, which passes the updated state into the widget. Try adding an effect that has &lt;FONT face="courier new,courier"&gt;props.state&lt;/FONT&gt; as a dependency and it should only fire when that changes. If you need to explicitly look for a change instead of blind-firing on a certain state you can try something like &lt;A href="https://stackoverflow.com/a/53446665" target="_self"&gt;this SO post&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2025 19:46:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597750#M508</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2025-03-20T19:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: React functional component component unmount useEffect</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597753#M509</link>
      <description>&lt;P&gt;Use a useEffect function without a return statement.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;useEffect(() =&amp;gt; {
  yourCode()
}, [props.state])&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 20 Mar 2025 19:47:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1597753#M509</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2025-03-20T19:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: React functional component component unmount useEffect</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1608274#M549</link>
      <description>&lt;P&gt;I know this got marked as a solution, but another option would be to take a snapshot of state before applying any of those changes, and perhaps catch the widget closing (perhaps a button to restore the layer view) that returns it to the previous state?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Apr 2025 20:43:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/react-functional-component-component-unmount/m-p/1608274#M549</guid>
      <dc:creator>TimWestern</dc:creator>
      <dc:date>2025-04-22T20:43:47Z</dc:date>
    </item>
  </channel>
</rss>

