Custom renderers for PubNub Chat Components for React Native

In some applications, using one of the themes and customizing styles might not be enough. You may need to completely change the markup of the components, either to modify the layout or add new, custom features.

If that's your case, you can use the most advanced and the most flexible option of customization - custom renderers. Most of the components come with one or multiple properties with names ending in renderer, like messageRenderer in the MessageList component.

These types of properties accept a function that should return an JSX structure. Input for the function differs depending on a particular renderer, but it's always the data used internally to create the default markup.

Sample usage

The code snippet below shows a sample usage of messageRenderer in the MessageList component that was mentioned earlier. We are using it to replace the default markup of each message. The function is provided with a message object (message itself, attachments, and reactions) along with:

  • Sender data (assuming it was either attached to the message or passed into Chat Provider)
  • Time when the message was sent
  • Edited text (if editing ever occurred)
Default features

If needed, the default features, like rendered attachments, might need to be implemented as well. Otherwise, they won't be shown at all.

function ExampleChat() {
const currentChannel = "example";

const renderMessage = (props: MessageRendererProps) => {
return (
<Text style={{ fontWeight: "bold" }}>{}</Text> {props.time}

return (
show all 22 lines
Last updated on
On this page