FredrikOseberg / react-chatbot-kit

MIT License
328 stars 157 forks source link

Can widgets be resused? The previous messages are getting overriden when widget is reused #104

Open puru0019 opened 2 years ago

puru0019 commented 2 years ago

Hi,

I am experimenting on react-chatbot-kit and it looks good. However I am facing one issue. When I am trying to reuse the same widget, The previous messages in chat boat are getting overridden.

Please have a look into following example. When I select python certification from below example chatbot I will be getting 4 options. Next if I select web development I will be getting 2 options and the previous 4 options from python certification are overridden with web development 2 options.

https://codesandbox.io/s/restless-frog-nmwzg9

Pinni05 commented 2 years ago

Hi @FredrikOseberg I am having the same issue when trying to reuse the same widget. Any suggestion for this?

FredrikOseberg commented 2 years ago

Hi @puru0019 and @Pinni05

This is due to how React works, if you rely on state in a widget, that widget will update whenever state is updated. What you'll need to do is to break the connection between the widget and the state, for example by taking a local copy in your widget of the state when the component mounts and use that to display the data.

GukeshChess commented 6 months ago

Hi @puru0019 and @Pinni05, Were you able to fix this? If yes, can you please provide a sandbox or a snippet