Ids of state component in callback

Hi I am wondering if it is possible to get the ids of a state object in a dash callback. Similar to triggered_id, but for a state object instead. Thanks

Hello @nik_2023,

You should know what the id of state based upon the variable association.

Or you could pull the prop id as a state.

Hi, out of curiosity: what would be a use case for this?

I just asked a similar question about bringing in the component IDs and their associated values as a dictionary pair.

I wanted to read data from multiple components of the same type. Most of my component ids are generated dynamically and thus it’s difficult to tell which ID I’m working with when I pull all the values into the callback. To get around that I had to retrieve the state of all the component IDs and values of the same component type and zip them together. I’m kind of relying (hoping) that Dash keeps the ids and values ordered the same when they are pulled in as a list. That way when I zip them the pairs are always matched correctly. Please tell me if that is a bad assumption.

Is there a better way to do this? As stated in my other post the ideal way would be to retrieve the id and corresponding value as a key, value dictionary.

Did you take a look at pattern matching callbacks?

Hi, so i figured it out. In the state callback I have something like this:
State({"type": "switch-connect-charger", "index": ALL}, "id")
This means I can get the index of the state object.

The use case is that I have dcc.Store where some of the keys correspond to the index of the state object. I was not aware when I wrote the message how I could extract the id from a state object in the callback but this resolved it :slight_smile: