import { useContext } from "react";
import { MessageInputContext } from "stream-chat-react-native";
const { sendMessage, toggleAttachmentPicker } = useContext(MessageInputContext);MessageInputContext
MessageInputContext is provided by Channel. If you are not familiar with the React Context API, see the React docs.
Best Practices
- Prefer
useMessageInputContextfor consistent access and typings. - Use context handlers (
sendMessage,editMessage) to keep behavior aligned with the SDK. - Keep input-related props stable to avoid re-renders while typing.
- Use
toggleAttachmentPickerand related helpers to keep picker state consistent. - Respect cooldowns and permissions before allowing sends or uploads.
Basic Usage
Consume MessageInputContext in any child of Channel:
Alternatively, use the useMessageInputContext hook.
import { useMessageInputContext } from "stream-chat-react-native";
const { sendMessage, toggleAttachmentPicker } = useMessageInputContext();Value
additionalTextInputProps
Extra props passed to the underlying TextInput in MessageInput.
| Type |
|---|
| object |
asyncMessagesLockDistance
Pixels the user must drag upward to lock recording and lift their finger without stopping it.
| Type | Default |
|---|---|
| Number | 50 |
asyncMessagesMinimumPressDuration
Minimum press duration (ms) on the record button to start voice recording.
| Type | Default |
|---|---|
| Number | 500 |
asyncMessagesMultiSendEnabled
When enabled, recordings don’t send immediately. They stack in the composer so users can send multiple voice recordings in one message.
| Type | Default |
|---|---|
| Boolean | true |
asyncMessagesSlideToCancelDistance
Pixels the user must drag toward the leading side to cancel voice recording.
| Type | Default |
|---|---|
| Number | 100 |
audioRecordingEnabled
Enable or disable audio recording.
| Type | Default |
|---|---|
| Boolean | false |
attachmentPickerBottomSheetHandleHeight
Height of the attachment picker bottom sheet handle.
| Type | Default |
|---|---|
| Number | 20 |
attachmentPickerBottomSheetHeight
Height of the attachment picker bottom sheet when open.
| Type | Default |
|---|---|
| Number | 40% of Window Height |
attachmentSelectionBarHeight
Height of the attachment selection bar in the attachment picker.
| Type | Default |
|---|---|
| Number | 52 |
compressImageQuality
Image compression quality before upload.
On iOS, values >= 0.8 usually keep quality while reducing size. A value of 0.8 can roughly halve file size vs 1.0.
| Type | Default |
|---|---|
| number 0 to 1 (1 is best quality) | iOS: 0.8 Android: 1 |
cooldownEndsAt
The time at which the active cool-down will end.
| Type |
|---|
| Date |
editMessage
Handles the edit message event on the message input by taking the new message as input and updating the message for the client.
| Type |
|---|
| Function |
The function takes an object as a parameter with the following properties:
| Parameter | Description |
|---|---|
localMessage | Contains the message data that will be shown in the UI immediately |
options | Contains options for sending/updating the message |
handleAttachButtonPress
Customize behavior when the AttachButton is pressed in the message input.
| Type |
|---|
() => void |
hasCameraPicker
Enable the camera picker in MessageInput.
| Type | Default |
|---|---|
| Boolean | true |
hasCommands
Enable commands in MessageInput.
| Type | Default |
|---|---|
| boolean | true |
hasFilePicker
Enable the file picker in MessageInput.
| Type | Default |
|---|---|
| Boolean | true |
hasImagePicker
Enable the image picker in MessageInput.
| Type | Default |
|---|---|
| Boolean | true |
sendMessage
Sends a composed message within MessageInput component to channel. This function is attached to onPress handler of SendButton. The message optimistically gets added to message list UI first, before actually making API call to server.
During this intermediate stage, MessageStatus component will display an indicator for "pending" state.
| Type |
|---|
| Function |
The function takes an object as a parameter with the following properties:
| Parameter | Description |
|---|---|
localMessage | Contains the message data that will be shown in the UI immediately |
message | Contains the data that will be sent to the backend |
options | Contains options for sending/updating the message |
closeAttachmentPicker
Dismiss the attachment picker, if its already open.
| Type |
|---|
| Function |
closePollCreationDialog
Function called whenever the close button is pressed on the poll creation modal. Has no effect if PollCreateContent is custom.
| Type |
|---|
| function |
doFileUploadRequest
inputBoxRef
Ref for TextInput component within MessageInput
| Type |
|---|
| React ref |
openAttachmentPicker
Opens the attachment picker bottom sheet, if its not open.
| Type |
|---|
| Function |
openPollCreationDialog
Called when the poll creation button is clicked in the attachment picker. Use it to override the default modal UI.
If overridden, a payload is passed with sendMessage from MessageInputContext for use in CreatePoll.
| Type |
|---|
| function |
| Parameter | Description |
|---|---|
| payload | { sendMessage } |
pickAndUploadImageFromNativePicker
Opens the native image picker and uploads the selected image.
| Type |
|---|
() => Promise<void> |
pickFile
Opens the native document/file picker and uploads the selected files.
| Type |
|---|
() => Promise<void> |
selectedPicker
Value is images (string), when image attachment picker is open else undefined.
| Type |
|---|
| 'images' | undefined |
setInputBoxRef
Setter function for inputBoxRef
| Type |
|---|
(ref) => void |
showPollCreationDialog
A boolean signifying whether the poll creation dialog is shown or not. Will always be false if PollCreateContent is custom.
| Type |
|---|
| boolean |
takeAndUploadImage
Function to click an image using the device camera and upload it.
| Type |
|---|
() => Promise<void> |
thread
Can be a LocalMessage or ThreadType. Setting it indicates a thread is open. Both types are interchangeable.
With Thread, this displays the thread. With the standard MessageList, it keeps singleton components in OverlayProvider in sync.
Set thread on all Channel components when a thread is open.
| Type |
|---|
| object |
toggleAttachmentPicker
Function to toggle attachment picker. By default, this function is attached to onPress handler for AttachButton.
| Type |
|---|
| Function |
uploadNewFile
Function to upload an attached file in MessageInput. This invokes the Message composer Attachment Manager's uploadFiles method to handle the file upload process.
This handles the abort controller to make sure that the upload can be cancelled if needed.
| Type |
|---|
(file: File) => Promise |
Components Props
AttachButton
Renders the attach button next to the input box.
| Type | Default |
|---|---|
| ComponentType | AttachButton |
AttachmentUploadPreviewList
Renders previews of attached files and images in MessageInput.
| Type | Default |
|---|---|
| ComponentType | AttachmentUploadPreviewList |
AudioAttachmentUploadPreview
Customize the audio attachment upload preview in MessageInput.
| Type | Default |
|---|---|
| ComponentType | AudioAttachmentUploadPreview |
AudioRecorder
Custom UI for audio recorder controls in MessageInput.
| Type | Default |
|---|---|
| ComponentType | AudioRecorder |
AudioRecordingInProgress
Custom UI for an in-progress audio recording in MessageInput (waveform, duration, etc.).
| Type | Default |
|---|---|
| ComponentType | AudioRecordingInProgress |
AudioRecordingLockIndicator
Custom lock indicator for audio recording in MessageInput.
| Type | Default |
|---|---|
| ComponentType | AudioRecordingLockIndicator |
AudioRecordingPreview
Custom UI to preview and play an audio recording in MessageInput.
| Type | Default |
|---|---|
| ComponentType | AudioRecordingPreview |
AudioRecordingWaveform
Custom waveform UI for audio recording in MessageInput.
| Type | Default |
|---|---|
| ComponentType | AudioRecordingWaveform |
AutoCompleteSuggestionHeader
Renders the autocomplete suggestion header.
| Type | Default |
|---|---|
| ComponentType | AutoCompleteSuggestionHeader |
AutoCompleteSuggestionItem
Renders an autocomplete suggestion item.
| Type | Default |
|---|---|
| ComponentType | AutoCompleteSuggestionItem |
AutoCompleteSuggestionList
Renders the autocomplete suggestion list.
| Type | Default |
|---|---|
| ComponentType | AutoCompleteSuggestionList |
AttachmentPickerBottomSheetHandle
Bottom sheet handle component for the attachment picker.
| Type | Default |
|---|---|
| ComponentType | undefined | AttachmentPickerBottomSheetHandle |
AttachmentPickerSelectionBar
Renders the attachment picker selection bar (image, file, camera icons).
| Type | Default |
|---|---|
| ComponentType | undefined | AttachmentPickerSelectionBar |
CameraSelectorIcon
Camera selector icon in the attachment selector bar.
| Type | Default |
|---|---|
| ComponentType | undefined | CameraSelectorIcon |
CooldownTimer
Renders a countdown timer for message send cooldowns in MessageInput.
| Type | Default |
|---|---|
| ComponentType | CooldownTimer |
CommandsButton
Renders the button next to the input box that opens the commands list.
| Type | Default |
|---|---|
| ComponentType | CommandsButton |
CommandInput
Renders the message input in an active command state.
| Type | Default |
|---|---|
| ComponentType | CommandInput |
CreatePollIcon
Create poll icon in the attachment selector bar.
| Type | Default |
|---|---|
| ComponentType | undefined | CreatePollIcon |
FileSelectorIcon
File selector icon in the attachment selector bar.
| Type | Default |
|---|---|
| ComponentType | undefined | FileSelectorIcon |
ImageSelectorIcon
Image selector icon in the attachment selector bar.
| Type | Default |
|---|---|
| ComponentType | undefined | ImageSelectorIcon |
VideoRecorderSelectorIcon
Video recorder selector icon in the attachment selector bar.
| Type | Default |
|---|---|
| ComponentType | undefined | VideoRecorderSelectorIcon |
FileAttachmentUploadPreview
Customize the file attachment upload preview in MessageInput.
| Type | Default |
|---|---|
| ComponentType | FileAttachmentUploadPreview |
ImageAttachmentUploadPreview
Customize the image attachment upload preview in MessageInput.
| Type | Default |
|---|---|
| ComponentType | ImageAttachmentUploadPreview |
VideoAttachmentUploadPreview
Customize the video attachment upload preview in MessageInput.
| Type | Default |
|---|---|
| ComponentType | VideoAttachmentUploadPreview |
AttachmentUploadProgressIndicator
Renders upload progress for images/files in the message input.
| Type | Default |
|---|---|
| ComponentType | AttachmentUploadProgressIndicator |
Input
Renders the UI for the enclosed MessageInput.
See Customizing Message Input.
| Type |
|---|
| ComponentType |
InputButtons
Renders action buttons (CommandsButton and AttachButton) on the left side of the MessageInput.
| Type | Default |
|---|---|
| ComponentType | InputButtons |
InputEditingStateHeader
Renders the header when editing a message in the input.
| Type | Default |
|---|---|
| ComponentType | InputEditingStateHeader |
InputReplyStateHeader
Renders the reply header in the message input.
| Type | Default |
|---|---|
| ComponentType | InputReplyStateHeader |
MoreOptionsButton
Renders the MessageInput “more options” button (for AttachButton, CommandsButton, etc.).
| Type | Default |
|---|---|
| ComponentType | MoreOptionsButton |
SendButton
Renders the send message button inside MessageInput.
| Type | Default |
|---|---|
| ComponentType | SendButton |
SendMessageDisallowedIndicator
Renders an indicator when the current user can’t send messages.
| Type | Default |
|---|---|
| ComponentType | SendMessageDisallowedIndicator |
ShowThreadMessageInChannelButton
Renders a checkbox in Thread that sets show_in_channel to true when checked.
| Type | Default |
|---|---|
| ComponentType | ShowThreadMessageInChannelButton |
StartAudioRecordingButton
Custom mic button for audio recording in MessageInput.
| Type | Default |
|---|---|
| ComponentType | StartAudioRecordingButton |
CreatePollContent
A custom UI component used to render the entire poll creation form. It has access to the CreatePollContext values by default through the useCreatePollContext hook.
| Type | Default |
|---|---|
| ComponentType | CreatePollContent |
- Best Practices
- Basic Usage
- Value
- additionalTextInputProps
- asyncMessagesLockDistance
- asyncMessagesMinimumPressDuration
- asyncMessagesMultiSendEnabled
- asyncMessagesSlideToCancelDistance
- audioRecordingEnabled
- attachmentPickerBottomSheetHandleHeight
- attachmentPickerBottomSheetHeight
- attachmentSelectionBarHeight
- compressImageQuality
- cooldownEndsAt
- editMessage
- handleAttachButtonPress
- hasCameraPicker
- hasCommands
- hasFilePicker
- hasImagePicker
- sendMessage
- closeAttachmentPicker
- closePollCreationDialog
- doFileUploadRequest
- inputBoxRef
- openAttachmentPicker
- openPollCreationDialog
- pickAndUploadImageFromNativePicker
- pickFile
- selectedPicker
- setInputBoxRef
- showPollCreationDialog
- takeAndUploadImage
- thread
- toggleAttachmentPicker
- uploadNewFile
- Components Props
- AttachButton
- AttachmentUploadPreviewList
- AudioAttachmentUploadPreview
- AudioRecorder
- AudioRecordingInProgress
- AudioRecordingLockIndicator
- AudioRecordingPreview
- AudioRecordingWaveform
- AutoCompleteSuggestionHeader
- AutoCompleteSuggestionItem
- AutoCompleteSuggestionList
- AttachmentPickerBottomSheetHandle
- AttachmentPickerSelectionBar
- CameraSelectorIcon
- CooldownTimer
- CommandsButton
- CommandInput
- CreatePollIcon
- FileSelectorIcon
- ImageSelectorIcon
- VideoRecorderSelectorIcon
- FileAttachmentUploadPreview
- ImageAttachmentUploadPreview
- VideoAttachmentUploadPreview
- AttachmentUploadProgressIndicator
- Input
- InputButtons
- InputEditingStateHeader
- InputReplyStateHeader
- MoreOptionsButton
- SendButton
- SendMessageDisallowedIndicator
- ShowThreadMessageInChannelButton
- StartAudioRecordingButton
- CreatePollContent