You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### 🎯 Goal
Currently the order of reactions in the `ReactionsList` depends of the
order of keys in the `reaction_counts` object returned by the backend.
This leads to unstable reaction order, which can change on page reloads,
or when the list of reactions changes.
We want to provide a way to customize this behavior, and to have a
stable order of reactions by default.
### 🛠 Implementation details
Added a new `MessageContext` property: `sortReactions`. It accepts two
reaction objects, and should return a positive/negative/zero numeric
value, similar to the `Array.prototype.sort` method.
The `sortReactions` prop can be passed both to `MessageList` and
`VirtualizedMessageList`, as well as to the `Message` component
directly. It will then be available via the `MessageContext`.
Copy file name to clipboardExpand all lines: docusaurus/docs/React/components/core-components/message-list.mdx
+27-22
Original file line number
Diff line number
Diff line change
@@ -73,6 +73,7 @@ The default `remark` plugins used by SDK are:
73
73
1.[`remark-gfm`](https://github.com/remarkjs/remark-gfm) - a third party plugin to add GitHub-like markdown support
74
74
75
75
The default `rehype` plugins (both specific to this SDK) are:
76
+
76
77
1. plugin to render user mentions
77
78
2. plugin to render emojis
78
79
@@ -166,56 +167,54 @@ If you would like to extend the array of plugins used to parse the markdown, you
166
167
It is important to understand what constitutes a rehype or remark plugin. A good start is to learn about the library called [`react-remark`](https://github.com/remarkjs/react-remark) which is used under the hood in our `renderText()` function.
It is also possible to define your custom set of allowed tag names for the elements rendered from the parsed markdown. To perform the tree transformations, you will need to use libraries like [`unist-builder`](https://github.com/syntax-tree/unist-builder) to build the trees and [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit-parents) or [`hast-util-find-and-replace`](https://github.com/syntax-tree/hast-util-find-and-replace) to traverse the tree:
Make sure that the elements you return have `key`, as they will be rendered as an array. It's also a good idea to wrap each element with `<li>` to keep your markup semantically correct.
@@ -621,9 +618,17 @@ The floating notification informing about unread messages will be shown when the
621
618
is shown only when viewing unread messages.
622
619
623
620
| Type | Default |
624
-
|---------|---------|
621
+
|-------|-------|
625
622
| boolean | false |
626
623
624
+
### sortReactions
625
+
626
+
Comparator function to sort reactions. Should have the same signature as the `sort` method for a string array.
By default, reactions are sorted alphabetically by type. You can change this behavior by passing a `sortReactions` prop to the `MessageList` (or `VirtualizedMessageList`).
125
+
126
+
In this example, we sort the reactions in the descending order by the number of users:
For better performance, keep this function memoized with `useCallback`, or declare it in either global or module scope.
146
+
122
147
## ReactionSelector Props
123
148
124
149
### additionalEmojiProps (removed in `11.0.0`)
@@ -276,6 +301,14 @@ If true, adds a CSS class that reverses the horizontal positioning of the select
276
301
| ------- | ------- |
277
302
| boolean | false |
278
303
304
+
### sortReactions
305
+
306
+
Comparator function to sort reactions. Should have the same signature as an array's `sort` method. This prop overrides the function stored in `MessageContext`.
0 commit comments