React Context hook does not update consumer
Hello, I have yet another react question :p
I am creating a datastore editor plugin and I have a list of datastore keys. Each of these is a button and when clicked, the data associated with that key should appear in the main editor. In order to do this I am using a context hook, and each key selection is a provider for the context hook. The main editor is a consumer of the hook. The context is created outside of the main component and passed in as a prop (I am not sure how else to do this, I could create the context inside the main component but I see no difference there):
continued below...
3 Replies
In the app component, each
key
of defaultContext is used to create a selection component:
The KioskObject components acts as a provider:
The way I currently have this set up does not work for some reason unknown to me. The button receives the click event and sets the context state properly but that change does not replicate up to the context. I was basing the code I have here off of this guide .Ok, nevermind, apparently the table being passed into setContext only contains
keys
...?
Ok, it turns out react consumes the props table's
key
member and when passed to the component it is nil. I renamed it to dsid
however the textlabel doesn't appear to update when the state is set in KioskObject