Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass more parameters in useDropzone #223

Open
ardalan-nhd opened this issue Apr 9, 2021 · 0 comments
Open

Pass more parameters in useDropzone #223

ardalan-nhd opened this issue Apr 9, 2021 · 0 comments

Comments

@ardalan-nhd
Copy link

Is there a way to pass more than three parameters to onDrop function? I mean i have access to accepted, rejected an synthetic event. But i need to pass an ID too and i can't figure out how.
Here's my code. As you can see i console.log(event.target.id) but it's always 1. But when i console.log(uploadable.id) it is 2
`import React, { useEffect, useState, useCallback, useMemo } from 'react';
import { useDropzone } from 'react-dropzone';
import Header2 from '../layout/header2';
import Sidebar from '../layout/sidebar';
import Footer2 from '../layout/footer2';
import axios from '../../axiosConfig'
import ContentBody from '../element/contentBody';
import lang from '../../langObject'

const language = localStorage.getItem('language')

const baseStyle = {
flex: 1,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
padding: '20px',
borderWidth: 2,
borderRadius: 2,
borderColor: '#eeeeee',
borderStyle: 'dashed',
background: 'transparent',
color: '#9d9d9d',
outline: 'none',
transition: 'border .24s ease-in-out'
};

const activeStyle = {
borderColor: '#2196f3'
};

const acceptStyle = {
borderColor: '#00e676'
};

const rejectStyle = {
borderColor: '#ff1744'
};

function DocumentsCreateUser() {
const [uploadables, setUploadables] = useState([])
const ref = useRef()
const [files, setFiles] = useState([])

const onDrop = useCallback((accepted, rejected, event, id) => {
    console.log(event)
}, [])

const {
    getRootProps,
    getInputProps,
    isDragActive,
    isDragAccept,
    isDragReject
} = useDropzone({ accept: 'image/*', onDrop: (accepted, rejected, e, id) => onDrop(accepted, rejected, e, id), multiple: false })

const style = useMemo(() => ({
    ...baseStyle,
    ...(isDragActive ? activeStyle : {}),
    ...(isDragAccept ? acceptStyle : {}),
    ...(isDragReject ? rejectStyle : {})
}), [
    isDragActive,
    isDragReject,
    isDragAccept
])

useEffect(() => {
    axios.get('/api/user/documents')
        .then((response) => {
            console.log(response)
            setUploadables(response.data.uploadables)
        })
    getRootProps().onDrop = console.log()
    console.log(getRootProps().onDrop)
}, [])

return (
    <div id="main-wrapper">
        <Header2 />
        <Sidebar />
        <ContentBody>
            <div class="container-fluid">
                <h3>Upload Documents</h3>

                <div class="row">
                    {uploadables.map((uploadable, index) => {
                        if (index === 0) {
                            console.log(uploadable.id)
                        }

                        return (
                            <div class="col-lg-6 col-md-12" key={uploadable.id}>
                                <div class="card">
                                    <div class="card-header">
                                        <h4 class="card-title">{uploadable[`title_${language}`]}</h4>
                                    </div>
                                    <div class="card-body">
                                        <p>{uploadable[`description_${language}`]}</p>
                                        <div class="mb-3" {...getRootProps({ style: style })}>
                                            <input {...getInputProps()} id={uploadable} />
                                            {
                                                isDragActive ?
                                                    <p>{lang.get('pages.dropFileHere')}</p> :
                                                    <p>{lang.get('pages.dragDropImageOrSelect')}</p>
                                            }
                                        </div>
                                    </div>
                                </div>
                            </div>
                        )
                    })}
                </div>
                <button class="btn btn-success">Upload Selected Documents</button>
            </div>
        </ContentBody>
        <Footer2 />
    </div>
)

}

export default DocumentsCreateUser`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant