Skip to content

Commit

Permalink
fix: rename field value to default value
Browse files Browse the repository at this point in the history
1. prop defaultValue ignore after it mounting
  • Loading branch information
egordidenko committed Feb 13, 2024
1 parent d2cce69 commit 51e9f21
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, {
} from 'react'
import uploadcare from 'uploadcare-widget'

import { defaultPreviewUrlCallback } from './default-preview-url-callback'
import {defaultPreviewUrlCallback} from './default-preview-url-callback'
import {
useCommitedCallback,
useCustomTabs,
Expand All @@ -19,7 +19,8 @@ const useWidget = (
{
id,
name,
value,
value, // @deprecated
defaultValue,
onFileSelect,
onChange,
onDialogOpen,
Expand Down Expand Up @@ -167,11 +168,11 @@ const useWidget = (
}, [widgetOptions])

useEffect(() => {
if (cachedValueRef.current !== value) {
widget.current.value(value)
if (cachedValueRef.current !== defaultValue) {
widget.current.value(defaultValue)
}
cachedValueRef.current = value
}, [value])
cachedValueRef.current = defaultValue
}, [])

Check warning on line 175 in src/uploader.js

View workflow job for this annotation

GitHub Actions / build

React Hook useEffect has a missing dependency: 'defaultValue'. Either include it or remove the dependency array

useEffect(() => {
if (uploadcare && tabsCss && typeof tabsCss === 'string') {
Expand All @@ -195,15 +196,15 @@ const useWidget = (
)

return useCallback(
() => <input type="hidden" ref={input} id={id} name={name} />,
() => <input type="hidden" ref={input} id={id} name={name}/>,
[id, name]
)
}

const Uploader = (props) => {
const Input = useWidget(props, uploadcare)

return <Input />
return <Input/>
}

export default Uploader

0 comments on commit 51e9f21

Please sign in to comment.