import { useContext } from "react";
import { MessageInputContext } from "stream-chat-react-native";
const { sendMessage, openAttachmentPicker } = 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
openAttachmentPickerandcloseAttachmentPickerhelpers 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, openAttachmentPicker } = useMessageInputContext();Value
additionalTextInputProps
Extra props passed to the underlying TextInput in MessageInput.
| Type |
|---|
| object |
allowSendBeforeAttachmentsUpload
When enabled, messages can be sent before all attachments have finished uploading.
| Type | Default |
|---|---|
| Boolean | - |
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 |
audioRecorderManager
Instance of AudioRecorderManager used to manage audio recording state internally.
| Type |
|---|
AudioRecorderManager |
audioRecordingEnabled
Enable or disable audio recording.
| Type | Default |
|---|---|
| Boolean | false |
attachmentPickerBottomSheetHeight
Height of the attachment picker bottom sheet when open.
| Type | Default |
|---|---|
| Number | 40% of Window Height |
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 |
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 |
createPollOptionGap
Vertical gap between poll options in the poll creation dialog.
| Type |
|---|
| Number |
deleteVoiceRecording
Deletes the current voice recording.
| Type |
|---|
() => Promise<void> |
doFileUploadRequest
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 |
inputBoxRef
Ref for TextInput component within MessageInput
| Type |
|---|
| React ref |
messageInputFloating
Whether the message input is floating or not.
| Type | Default |
|---|---|
| Boolean | false |
messageInputHeightStore
Store instance for tracking the message input height.
| Type |
|---|
MessageInputHeightStore |
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> |
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 |
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 |
startVoiceRecording
Starts a new voice recording session.
| Type |
|---|
() => Promise<boolean | undefined> |
stopVoiceRecording
Stops the current voice recording.
| Type |
|---|
() => Promise<void> |
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 |
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 |
uploadVoiceRecording
Uploads the current voice recording. When multiSendEnabled is true, the recording stacks in the composer instead of being sent immediately.
| Type |
|---|
(multiSendEnabled: boolean) => Promise<void> |
Components Props
AttachButton
Renders the attach button next to the input box.
| Type | Default |
|---|---|
| ComponentType | AttachButton |
AttachmentPickerSelectionBar
Renders the attachment picker selection bar (image, file, camera icons).
| Type | Default |
|---|---|
| ComponentType | undefined | AttachmentPickerSelectionBar |
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 |
CooldownTimer
Renders a countdown timer for message send cooldowns in MessageInput.
| Type | Default |
|---|---|
| ComponentType | CooldownTimer |
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 |
FileAttachmentUploadPreview
Customize the file attachment upload preview in MessageInput.
| Type | Default |
|---|---|
| ComponentType | FileAttachmentUploadPreview |
FileUploadInProgressIndicator
Renders a progress indicator for file uploads in MessageInput.
| Type |
|---|
| ComponentType |
FileUploadNotSupportedIndicator
Renders an indicator when file upload is not supported.
| Type |
|---|
| ComponentType |
FileUploadRetryIndicator
Renders a retry indicator for failed file uploads.
| Type |
|---|
| ComponentType |
ImageAttachmentUploadPreview
Customize the image attachment upload preview in MessageInput.
| Type | Default |
|---|---|
| ComponentType | ImageAttachmentUploadPreview |
ImageUploadInProgressIndicator
Renders a progress indicator for image uploads in MessageInput.
| Type |
|---|
| ComponentType |
ImageUploadNotSupportedIndicator
Renders an indicator when image upload is not supported.
| Type |
|---|
| ComponentType |
ImageUploadRetryIndicator
Renders a retry indicator for failed image uploads.
| Type |
|---|
| ComponentType |
Input
Renders the UI for the enclosed MessageInput.
See Customizing Message Input.
| Type |
|---|
| ComponentType |
InputButtons
Renders action buttons (AttachButton) on the left side of the MessageInput.
| Type | Default |
|---|---|
| ComponentType | InputButtons |
MessageComposerLeadingView
Custom UI component to override the leading side of the composer container.
| Type |
|---|
| ComponentType |
MessageComposerTrailingView
Custom UI component to override the trailing side of the composer container.
| Type |
|---|
| ComponentType |
MessageInputHeaderView
Custom UI component to override the message input header content.
| Type |
|---|
| ComponentType |
MessageInputLeadingView
Custom UI component to override the leading side of the input row.
| Type |
|---|
| ComponentType |
MessageInputTrailingView
Custom UI component to override the trailing side of the input row.
| Type |
|---|
| ComponentType |
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 |
StopMessageStreamingButton
Custom UI component to render a button that stops message streaming (for AI-generated responses).
| Type |
|---|
ComponentType | null |
VideoAttachmentUploadPreview
Customize the video attachment upload preview in MessageInput.
| Type | Default |
|---|---|
| ComponentType | VideoAttachmentUploadPreview |
- Best Practices
- Basic Usage
- Value
- additionalTextInputProps
- allowSendBeforeAttachmentsUpload
- asyncMessagesLockDistance
- asyncMessagesMinimumPressDuration
- asyncMessagesMultiSendEnabled
- asyncMessagesSlideToCancelDistance
- audioRecorderManager
- audioRecordingEnabled
- attachmentPickerBottomSheetHeight
- compressImageQuality
- closeAttachmentPicker
- closePollCreationDialog
- createPollOptionGap
- deleteVoiceRecording
- doFileUploadRequest
- editMessage
- handleAttachButtonPress
- hasCameraPicker
- hasCommands
- hasFilePicker
- hasImagePicker
- inputBoxRef
- messageInputFloating
- messageInputHeightStore
- openAttachmentPicker
- openPollCreationDialog
- pickAndUploadImageFromNativePicker
- pickFile
- sendMessage
- setInputBoxRef
- showPollCreationDialog
- startVoiceRecording
- stopVoiceRecording
- takeAndUploadImage
- thread
- uploadNewFile
- uploadVoiceRecording
- Components Props
- AttachButton
- AttachmentPickerSelectionBar
- AttachmentUploadPreviewList
- AudioAttachmentUploadPreview
- AudioRecorder
- AudioRecordingInProgress
- AudioRecordingLockIndicator
- AudioRecordingPreview
- AudioRecordingWaveform
- AutoCompleteSuggestionHeader
- AutoCompleteSuggestionItem
- AutoCompleteSuggestionList
- CooldownTimer
- CreatePollContent
- FileAttachmentUploadPreview
- FileUploadInProgressIndicator
- FileUploadNotSupportedIndicator
- FileUploadRetryIndicator
- ImageAttachmentUploadPreview
- ImageUploadInProgressIndicator
- ImageUploadNotSupportedIndicator
- ImageUploadRetryIndicator
- Input
- InputButtons
- MessageComposerLeadingView
- MessageComposerTrailingView
- MessageInputHeaderView
- MessageInputLeadingView
- MessageInputTrailingView
- SendButton
- SendMessageDisallowedIndicator
- ShowThreadMessageInChannelButton
- StartAudioRecordingButton
- StopMessageStreamingButton
- VideoAttachmentUploadPreview