Skip to content

Commit

Permalink
fix(uploader): image refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
emgk committed Aug 15, 2024
1 parent de6fecc commit e40bb3d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/ui/uploader/src/uploader-file.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-nocheck
import React, { memo } from "react"
import React, { memo, useEffect, useState } from "react"

import { FileCheck } from "@wpmudev/sui-icons"
import { Button } from "@wpmudev/sui-button"
Expand All @@ -21,6 +21,17 @@ import { useStyles } from "@wpmudev/sui-hooks"
const UploaderFile: React.FC<UploaderFileProps> = React.memo(
({ id, file, onRemove, _style = {} }: UploaderFileProps): JSX.Element => {
const { suiInlineClassname } = useStyles(_style)
const [previewUrl, setPreviewUrl] = useState()

const updatePreviewUrl = () => {
if (isImageFile(file?.type)) {
setPreviewUrl(getFileImagePreview(file))
}
}

// Update preview url
useEffect(updatePreviewUrl, [])

Check warning on line 33 in packages/ui/uploader/src/uploader-file.tsx

View workflow job for this annotation

GitHub Actions / code-quality

React Hook useEffect has a missing dependency: 'file'. Either include it or remove the dependency array. If 'setPreviewUrl' needs the current value of 'file', you can also switch to useReducer instead of useState and read 'file' in the reducer
useEffect(updatePreviewUrl, [file])

// @todo: add error variation support
return (
Expand All @@ -35,7 +46,7 @@ const UploaderFile: React.FC<UploaderFileProps> = React.memo(
role="img"
className="sui-uploader__file--image"
style={{
backgroundImage: `url(${getFileImagePreview(file)})`,
backgroundImage: `url(${previewUrl})`,
}}
/>
) : (
Expand Down

0 comments on commit e40bb3d

Please sign in to comment.