Skip to content

Instantly share code, notes, and snippets.

@yoavniran
Last active May 6, 2024 12:31
Show Gist options
  • Save yoavniran/f3b6e3f14a67d7a0ddcae3df82fc60b9 to your computer and use it in GitHub Desktop.
Save yoavniran/f3b6e3f14a67d7a0ddcae3df82fc60b9 to your computer and use it in GitHub Desktop.
React-Uploady preview with progress demo - CustomImagePreview.jsx
import styled from "styled-components"
import { useItemProgressListener } from "@rpldy/uploady";
const PreviewImage = styled.img`
margin: 5px;
max-width: 200px;
height: auto;
transition: opacity 0.4s;
${({ completed }) => `opacity: ${completed / 100};`}
`;
const CustomImagePreview = ({ id, url }) => {
const [completed, setCompleted] = useState(0);
useItemProgressListener(item => {
if (item.id === id) {
setCompleted(item.completed);
}
});
return <PreviewImage src={url} completed={completed} />;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment