Closed succinct0274 closed 6 months ago
Hi @succinct0274. The state hook (useState) automatically re-renders the component. If Deep Chat is inside this component, it will also be re-rendered from scratch.
There are multiple ways you can prevent this from happening:
let talked = false;
This is a common problem when working with React/NextJs and hopefully the above solutions help. Let me know if you need more assistance. Thanks!
I will be closing this issue due to no recent activity on it. If you have any further questions in regards to the same topic - feel free to comment below, otherwise you can create a new issue. Thanks!
My solution is to use Memo to skip re-rendering when props don't change.
Basically, define this outside of the component
const MemoDeepChat = memo(DeepChat);
function MyComponet() {
<MemoDeepChat .../>
}
and make sure the props don't change. Note that for array and object props we need to make sure a new object is not created in a render.
Hi @OvidijusParsiunas, I found that the use of
useState
function in the handler or interceptor will cause the reload of the page and the messages will be all lost. Below is a code snippet that can reproduce the issue given your nextjs example provided in example-servers directory:I am not pretty sure the what root cause is. It would be great if you can give some advices to circumvent this. Thank you so much in advance.