Skip to main content

Custom Header Component

Pass renderHeader prop a function that returns JSX.

import React, { useState } from 'react';
import { Chatty } from 'react-native-chatty';

export default function MyReactPage() {
const [messages, setMessages] = useState()
const text = useRef()

const onPressSend = (data) => {
// Implement

socket.send(data)
}

return (
<Chatty
messages={messages}
headerProps={{
id: 0,
username: "Muhammed Kaplan",
avatar: {
uri: "https://blalala.com"
}
}}
footerProps={{
// To prevent any unnecessary re-rendering, we're using ref instead of states.
onChangeText: (_text) => text.current = _text,
onPressSend
}}
renderHeader={props => (
<View>
<Text> Custom header! {props.user.username}</Text>
</View>
)}
/>
);
}