useAttachments
- Description
- Params and Return
- Example
Hook to add and remove attachments from the attachment list
Param / Return | Description |
---|---|
returns | the attachmentlist state and the remove and add attachment functions |
How to use the useAttachments component
const [attachmentsList, addAttachment, removeAttachment] = useAttachments()
useEffect(() => {
// if a file was just added, update attachmentsList and clear the route params for attachmentFileToAdd
if (!_.isEmpty(attachmentFileToAdd) && !attachmentsList.includes(attachmentFileToAdd)) {
addAttachment(attachmentFileToAdd)
navigation.setParams({ attachmentFileToAdd: {} })
}
}, [attachmentFileToAdd, attachmentsList, addAttachment, navigation])
{
fieldType: FieldType.FormAttachmentsList,
fieldProps: {
originHeader: t('secureMessaging.drafts.edit'),
removeOnPress: removeAttachment,
largeButtonProps:
attachmentsList.length < theme.dimensions.maxNumMessageAttachments
? {
label: t('secureMessaging.formMessage.addFiles'),
a11yHint: t('secureMessaging.formMessage.addFiles.a11yHint'),
onPress: onAddFiles,
}
: undefined,
attachmentsList,
a11yHint: t('secureMessaging.attachments.howToAttachAFile.a11y'),
},