You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
While trying to respond to certain message values that will trigger custom state for our version of WebChat, the onNewMessage event handler isn't able to read ANY of the values setup with useState in WebChat.tsx.
Describe the solution you'd like
Having wracked my brain over these coals for the past 2 days, besides someone else anticipating the need, I'm at a loss. Everything I have tried so far has failed. I can call the set functions inside of a window.setTimeout with a 50 millisecond interval, and those do work, but the need, in this case, is to read the values inside the event, not just set them. All the useState values show up inside the event with their initial values. This also includes the state values from the store, I tried it both ways, they all show only the initial values.
Describe alternatives you've considered
First, I attempted to pull the onNewMessage function out into a property, that I would then reset ever render of the chat control in an attempt to keep the reference current. I even attempted to wrap the onNewMessage function in a useRef, and then tweaked the onNewMessage function in the OmnichannelSDK (like so)
and then manually re-set the ref on every re-render of the WebChat component and still no joy.
Additional context
This problem sounds simple. At least, that's what my boss says. Copilot and ChatGPT seem to disagree with him, however.
The text was updated successfully, but these errors were encountered:
OK. it's terribly yucky... but here is what I did:
// we maintain separate instances of the store for each chat component and pass them in as properties
const { state, dispatch } = useContext(props.Store);
if (!window.ourChatStates) {
window.ourChatStates = {};
}
window.ourChatStates[props.id] = state;
We have a custom type for our window object, and I added a dictionary to hold the state bag (a dictionary because we have multiple instances of the chat control in our app, distinguished by an id property). Each time through the function, the current state is then being written into the dictionary, and from there, the event handler is able to access the current values.
Given the disconnected nature of the underlying SDK, and the tendency of react to re-render itself, I don't know that I see a better option, at this point. I have to go home and take a shower. I feel dirty.
Is your feature request related to a problem? Please describe.
While trying to respond to certain message values that will trigger custom state for our version of WebChat, the onNewMessage event handler isn't able to read ANY of the values setup with useState in WebChat.tsx.
Describe the solution you'd like
Having wracked my brain over these coals for the past 2 days, besides someone else anticipating the need, I'm at a loss. Everything I have tried so far has failed. I can call the set functions inside of a window.setTimeout with a 50 millisecond interval, and those do work, but the need, in this case, is to read the values inside the event, not just set them. All the useState values show up inside the event with their initial values. This also includes the state values from the store, I tried it both ways, they all show only the initial values.
Describe alternatives you've considered
First, I attempted to pull the onNewMessage function out into a property, that I would then reset ever render of the chat control in an attempt to keep the reference current. I even attempted to wrap the onNewMessage function in a useRef, and then tweaked the onNewMessage function in the OmnichannelSDK (like so)
and then manually re-set the ref on every re-render of the WebChat component and still no joy.
Additional context
This problem sounds simple. At least, that's what my boss says. Copilot and ChatGPT seem to disagree with him, however.
The text was updated successfully, but these errors were encountered: