Created
August 25, 2019 18:10
-
-
Save Ifmr24/f3684a7abd332b8a923f9cfb1e24a804 to your computer and use it in GitHub Desktop.
S3 Upload React Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useRef } from 'react'; | |
import { uploadFileThunk } from '../../../store/upload/actions'; | |
import { useDispatch, useSelector } from 'react-redux'; | |
const ComponentName = () => { | |
const uploadInput = useRef(); | |
const dispatch = useDispatch(); | |
const upload = useSelector(state => state.upload) | |
return ( | |
<div className="row"> | |
<div className="form-group"> | |
<input ref={uploadInput} type="file" className='form-control' /> | |
</div> | |
<div className="form-group"> | |
<button className='btn btn-success' onClick={() => dispatch(uploadFileThunk(uploadInput, 'images'))}> Upload File </button> | |
</div> | |
<div> | |
{upload.success && ( | |
<span> | |
<br/> | |
<p>File: <a href={upload.url} target='_blank'> {upload.url} </a></p> | |
</span> | |
)} | |
</div> | |
</div> | |
); | |
} | |
export default ComponentName; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment