Skip to content

in WebChat.tsx, in the onNewMessage event handler, what was the plan for interacting with useState values (both getting and setting)? #492

Open
@MisterRichards

Description

@MisterRichards

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)
image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions