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
Copy file name to clipboardExpand all lines: docusaurus/docs/reactnative/guides/attachment_customizations.mdx
+32-7Lines changed: 32 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -335,26 +335,51 @@ export default function App() {
335
335
}
336
336
```
337
337
338
-
## Memoization handler for custom attachment properties
338
+
## Handling Custom Properties On Attachment
339
339
340
-
When we add a custom property to the attachment format, and the data is changed around that property, the component is not rerendered by default. This should be fixed by passing a custom handler to the prop [`isAttachmentEqual`](../core-components/channel.mdx#isattachmentequal) to [Channel](../core-components/channel.mdx) component.
341
-
The logic should be implemented by the user by itself and must be similar to an equality check function we pass to a [React.memo](https://reactjs.org/docs/react-api.html#reactmemo) as a second argument.
340
+
Default UI components and context providers from the SDK are memoized for performance purpose, and will not trigger re-renders upon updates to
341
+
custom properties on attachment. Please refer to [memoization guide](../customization/custom_components.mdx#equality) for reference.
342
342
343
-
Eg: Suppose we add a `customField` property to the attachment object. We want to use the value of this field from the message object and have an update in the UI every time the property's value changes. We can do this by implementing a memoization handler for this field as below:
343
+
Eg: Suppose we add a `customField` property to the attachment object and use it the UI in custom `Card` component.
344
+
345
+
```tsx
346
+
<Channel
347
+
Card={attachment=> {
348
+
return (
349
+
<View>
350
+
<Text>{attachment.customField}</Text>
351
+
</View>
352
+
);
353
+
}}
354
+
/>
355
+
```
356
+
357
+
In this example, if you try to update `customField` on particular attachment from backend (or anywhere), you will not see it updated on UI until you refresh the chat.
358
+
359
+
The reason being, the default memoization logic only checks for fixed set of properties on attachment, and doesn't check for custom properties.
360
+
361
+
This can be solved by providing a function which checks for changes in custom properties which you may have been defined on attachment.
0 commit comments