Skip to content

Instantly share code, notes, and snippets.

View yoavniran's full-sized avatar
📖
Writing. Code & Prose

Yoav Niran yoavniran

📖
Writing. Code & Prose
View GitHub Profile
@yoavniran
yoavniran / useIsMounted.js
Created June 16, 2021 07:53
useIsMounted React hook
import { useEffect, useRef, useCallback } from "react";
const useIsMounted = () => {
const mountedRef = useRef(true);
useEffect(() => {
return () => {
mountedRef.current = false;
};
}, []);
@yoavniran
yoavniran / usePasteUpload.jsx
Created March 21, 2021 12:49
react-uploady usePasteUpload custom hook example
import React from "react";
import Uploady from "@rpldy/uploady";
import { usePasteUpload } from "@rpldy/upload-paste";
const ElementPaste = (props) => {
const containerRef = useRef(null);
const onPasteUpload = useCallback(({ count }) => {
console.log("ELEMENT PASTE-TO-UPLOAD files: ", count);
}, []);
@yoavniran
yoavniran / paste-to-upload.jsx
Created March 21, 2021 12:15
react-uploady paste to upload example
import React from "react";
import styled from "styled-components";
import Uploady from "@rpldy/uploady";
import UploadDropZone from "@rpldy/upload-drop-zone";
import withPasteUpload from "@rpldy/upload-paste";
const StyledDropZone = styled(UploadDropZone)`
width: 400px;
height: 400px;
border: 1px solid #000;
@yoavniran
yoavniran / App.styles.jxs
Created September 14, 2020 11:51
react-native uploady demo - styles
const styles = StyleSheet.create({
uploadedImage: {
width: 400,
height: 400,
resizeMode: 'cover',
},
body: {
backgroundColor: "#ffffff",
},
sectionContainer: {
@yoavniran
yoavniran / app.upload.jsx
Created September 14, 2020 11:50
react-native uploady demo - upload
const Upload = () => {
const [uploadUrl, setUploadUrl] = useState(false);
const uploadyContext = useContext(UploadyContext);
useItemFinishListener((item) => {
const response = JSON.parse(item.uploadResponse.data);
console.log(`item ${item.id} finished uploading, response was: `, response);
setUploadUrl(response.url);
});
@yoavniran
yoavniran / App.jsx
Last active September 14, 2020 12:05
react-native uploady demo - app
import React, { useState, useCallback, useContext } from "react";
import { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, Button, ImageBackground, Image } from "react-native";
import DocumentPicker from "react-native-document-picker/index";
import NativeUploady, {
UploadyContext,
useItemFinishListener,
useItemStartListener,
useItemErrorListener,
@yoavniran
yoavniran / ItemPreviewWithCrop.jsx
Last active July 8, 2020 20:55
ItemPreviewWithCrop.jsx - react-uploady demo
import ReactCrop from "react-image-crop";
import { withRequestPreSendUpdate, useItemFinalizeListener } from "@rpldy/uploady";
import { PREVIEW_TYPES } from "@rpldy/upload-preview";
import cropImage from "./image-crop-helper";
const ItemPreviewWithCrop = withRequestPreSendUpdate(props => {
const { id, url, isFallback, type, updateRequest, requestData, previewMethods } = props;
const [finished, setFinished] = useState(false);
const [crop, setCrop] = useState(null);
@yoavniran
yoavniran / UploadWithCrop.jsx
Last active July 8, 2020 15:54
UploadWithCrop.jsx - react-uploady demo
import Uploady from "@rpldy/uploady";
import UploadButton from "@rpldy/upload-button";
import UploadPreview from "@rpldy/upload-preview";
export default function UploadWithCrop() {
const previewMethodsRef = useRef();
return (
<Uploady
destination={{ url: "[upload-url]" }}
@yoavniran
yoavniran / UploadWithProgressPreview.jsx
Created May 21, 2020 21:35
React-Uploady preview with progress demo - UploadWithProgressPreview.jsx
import UploadButton from "@rpldy/upload-button";
import UploadPreview from "@rpldy/upload-preview";
import CustomImagePreview from "./CustomImagePreview";
const UploadWithProgressPreview = () => {
const getPreviewProps = useCallback(item => ({ id: item.id }), []);
return (
<>
<UploadButton>Upload Files</UploadButton>
@yoavniran
yoavniran / CustomImagePreview.jsx
Last active May 6, 2024 12:31
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};`}