Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting state in React resets to initial state. #154

Closed
oluvvafemi opened this issue Mar 29, 2024 · 2 comments
Closed

Setting state in React resets to initial state. #154

oluvvafemi opened this issue Mar 29, 2024 · 2 comments
Assignees
Labels
advice Information how to use/implement the component

Comments

@oluvvafemi
Copy link

Anytime I set state in React, for example in responseInterceptors, I lose the message and the component rerenders.

const responseInterceptor = (response) => {
  if (response.done) {
    setSomeValue('')
  }
}

For some cases, I set a global variable as a workaround. But is there a solution for when you really need to set a state.

@OvidijusParsiunas
Copy link
Owner

OvidijusParsiunas commented Mar 29, 2024

Hey @oluvvafemi.

This is a standard React practice as changing the state of a component will automatically re-render all of the elements (including Deep Chat) inside it - as well as its message state.
The current best solution at the moment is indeed storing the relevant state such as messages inside external state such as an external variable, browser storage, state library or cache. (The DeepChat Playground uses localstorage to retain all data during re-renders and persist it through multiple client sessions, code here)

Looking into the future, I am very inclined to create a solution that would allow the storage of state through configuration so that devs would no longer need to worry about integrating solutions for their state. I have to get through a couple of features before I can get to that one, but I am very committed to exploring it.

If you have any further questions regarding this let me know. Thanks!

@OvidijusParsiunas OvidijusParsiunas self-assigned this Mar 29, 2024
@OvidijusParsiunas OvidijusParsiunas added the advice Information how to use/implement the component label Mar 29, 2024
@oluvvafemi
Copy link
Author

Thank you @OvidijusParsiunas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
advice Information how to use/implement the component
Projects
None yet
Development

No branches or pull requests

2 participants