Select to view content in your preferred language

How to programmatically get another widget's current state?

636
3
11-17-2023 09:46 AM
RyanCoodey
Frequent Contributor

I am trying to get the current state of an out of the box widget (filter) but not finding a way to get it. I can easily set the state of that widget with: getAppStore().dispatch(appActions.widgetConfigUpgraded("widget_65", config)). But how can I get the current state from "widget_65" (which is inside a sidebar and navigation section if that matters)?

  1. getAppStore().getState().widgetsRuntimeInfo?.["widget_65"]?.state
    1. state is never set. The runtime info only has one property for isClassLoaded which is true.
  2. getAppStore().getState().widgetsState["widget_65"]
    1. widgetsState does not contain the widget, it only has a list and the sidebar. Neither which seem to expose their state either.
  3. getAppStore().getState().appConfig.widgets["widget_65"]
    1. I can get the state from this, but it is not the current state and is the initially loaded one, which makes sense coming from appConfig.
  4. WidgetManager.getInstance() not seeing any option in it to get the state.
  5. Can I use getAppStore().subscribe, not seeing how to get the state though.

I feel like I am missing something simple, any advice is greatly appreciated!

 

0 Kudos
3 Replies
JeffreyThompson2
MVP Regular Contributor

If I am remembering my React quirks correctly, state is an internal property to each component and not accessible outside of the component.

GIS Developer
City of Arlington, Texas
RyanCoodey
Frequent Contributor

I was afraid of that, thanks for that information @JeffreyThompson2. Seems backwards that they let you set another components state but won't let you read it.

I am new to React, probably should take a step back and learn it better first. Thanks again!

0 Kudos
JarrettGreen
Regular Contributor

@RyanCoodey I'm stuck with this as well. I'm using DataSourceComponent to listen for data source selection changes but only want to do this if my OOTB Search widget is active/open. Were you able to find a way to get the state of other widgets from your custom widget?

0 Kudos