Is your feature request related to a problem? Please describe.
Current implementation of MessageList uses local state of messages, which is used to render items in EndlessList. However, the state of messages array can be stored in state management library on top of MessageList, so this local state becomes unnecessary duplication. It would be nice to have such API that will give the possibility to store all messages only in one place, for example, in state management library.
Now useMessages hook is responsible for:
- Behavior when scroll top or bottom is reached. Now it fetches messages and merges them with previous array (using
useBoundedArray)
- Scrolling to bottom on mount (if there was no initial search)
- Handling incoming / outcoming message and pushing it in the rendered array of messages
- Search behavior: initial search rendering, handling of received, next and previous search results.
If the state of rendered items moves outside MessageList, then we need to provide an API to update state.
Describe the solution you'd like
Example with use of react-suspended-query: https://codesandbox.io/s/endless-list-suspense-kfgkh1?file=/src/EndlessList.tsx
In this example the main point is that we need to change the state of query parameters with startTransition, and then this change will cause react-suspended-query to throw a Promise. When promise is pending, React will render previous list. And after promise is resolved, new array renders.
However, this is only one of many patterns of state management, so rchat should not make any transitions or something similar.
The API of MessageList should notify that bounds of rendered messages has been changed. To take the most general case, it is possible to notify about changed bounds in the following way: send how many messages to render before ITEM and how many messages to render after ITEM. This approach is suitable both for scrolling top / bottom and for searching messages.
Is your feature request related to a problem? Please describe.
Current implementation of
MessageListuses local state of messages, which is used to render items inEndlessList. However, the state of messages array can be stored in state management library on top ofMessageList, so this local state becomes unnecessary duplication. It would be nice to have such API that will give the possibility to store all messages only in one place, for example, in state management library.Now
useMessageshook is responsible for:useBoundedArray)If the state of rendered items moves outside
MessageList, then we need to provide an API to update state.Describe the solution you'd like
Example with use of
react-suspended-query: https://codesandbox.io/s/endless-list-suspense-kfgkh1?file=/src/EndlessList.tsxIn this example the main point is that we need to change the state of query parameters with
startTransition, and then this change will causereact-suspended-queryto throw a Promise. When promise is pending, React will render previous list. And after promise is resolved, new array renders.However, this is only one of many patterns of state management, so
rchatshould not make any transitions or something similar.The API of
MessageListshould notify that bounds of rendered messages has been changed. To take the most general case, it is possible to notify about changed bounds in the following way: send how many messages to render before ITEM and how many messages to render after ITEM. This approach is suitable both for scrolling top / bottom and for searching messages.