OvidijusParsiunas / deep-chat

Fully customizable AI chatbot component for your website
https://deepchat.dev
MIT License
1.27k stars 176 forks source link

chatElementRef not working in React useEffect #48

Closed nishit-g closed 7 months ago

nishit-g commented 7 months ago

I am trying to use htmlClassUtilities in react app, but am not able to get desired results. I tried a lot but still no luck.

Can some one help me with this ?

Sandbox url

OvidijusParsiunas commented 7 months ago

Hi @nishit-g. Thankyou for sharing your sandbox.

The first issue with the code you provided is that you are using htmlClassUtils property, this should be changed to htmlClassUtilities.

Second issue is that useEffect appears to run too late for new properties to be applied. Hence, when chatElementRef.htmlClassUtilities is used it does not change anything in the component. I would instead recommend you to reference the htmlClassUtilities in a const variable or inline it like htmlClassUtilities={{. See the live React example.

Finally, whilst the refreshMessages method is ok to be used in useEffect, it refreshes text messages only (for the highlight.js to color any content that contains MarkDown code), so it will not change html messages.

Hopefully this makes sense. Let me know if you need any more help.

nishit-g commented 7 months ago

Thanks a lot @OvidijusParsiunas , got it working finally !