Skip to content

Commit

Permalink
fix: don't pass metadataCallback to the options if metadata present
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Dec 23, 2022
1 parent 213c223 commit 7deece8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ The option can be used to set metadata object associated with the uploaded file.

Note that metadata supports `string` values only, any non-string value will be converted to `string`, including `boolean`, `number`, `null` and `undefined`.

**WARNING**: If this option is specified, option `metadataCallback` will be overridden (without merging).
This is opposite from the uploadcare-widget's behavior.

See [Metadata docs][uc-docs-metadata] for details.

<br>
Expand All @@ -149,8 +152,6 @@ See [Metadata docs][uc-docs-metadata] for details.

Defines the function that specifies the actual metadata object a file uploader should use to associate with the uploaded file. It's helpful in the case of dynamic metadata object.

If this option is specified, option `metadata` will be overridden (without merging).

Note that metadata supports `string` values only, any non-string value will be converted to `string`, including `boolean`, `number`, `null` and `undefined`.

See [Metadata docs][uc-docs-metadata] for details.
Expand Down
13 changes: 10 additions & 3 deletions src/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ const useDialog = (props, uploadcare) => {
multipleMax: restProps.multiple ? undefined : 1,
...restProps,
multiple: true,
metadataCallback: metadataCommitedCallback,
metadataCallback: restProps.metadata
? undefined
: metadataCommitedCallback,
previewUrlCallback: previewUrlCommitedCallback
}
)
Expand Down Expand Up @@ -137,8 +139,13 @@ const useDialog = (props, uploadcare) => {
dialogApi.fileColl.onReplace.remove(onChangeWrapper)
dialogApi.fileColl.onSort.remove(onChangeWrapper)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [...Object.values(restProps), onTabChangeCallback, onChangeCallback, onProgressCallback])
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
...Object.values(restProps),
onTabChangeCallback,
onChangeCallback,
onProgressCallback
])

useImperativeHandle(
apiRef,
Expand Down
4 changes: 3 additions & 1 deletion src/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ const useWidget = (
const inputEl = input.current
widget.current = uploadcare.Widget(inputEl, {
...widgetOptions,
metadataCallback: metadataCommitedCallback,
metadataCallback: widgetOptions.metadata
? undefined
: metadataCommitedCallback,
previewUrlCallback: previewUrlCommitedCallback
})

Expand Down

0 comments on commit 7deece8

Please sign in to comment.