Last active
December 6, 2018 18:07
-
-
Save frikky/2aeb61aaf5c23eabd06296e12c99fcfe to your computer and use it in GitHub Desktop.
A post request example for blog
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, {useState} from 'react'; | |
const App = props => { | |
const name = "@frikkylikeme" | |
const url = "https://medium.com" | |
return ( | |
<div> | |
<Functionname url={url} name={name} {...props} /> | |
</div> | |
); | |
} | |
const Functionname = props => { | |
const {url, name} = props | |
const [file, setFile] = useState(""); | |
const uploadFile = () => { | |
fetch(url, { | |
method: "POST", | |
data: file, | |
}) | |
.then(response => { | |
console.log(response) | |
}) | |
.catch(error => { | |
console.log(error) | |
}) | |
} | |
return ( | |
<div> | |
<p>{name}</p> | |
<input type="file" name="fieldname" onChange={event => setFile(event.target.files[0])} /> | |
<button onClick={file => uploadFile(file)}>Upload</button> | |
</div> | |
) | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment