Skip to content

Instantly share code, notes, and snippets.

@frikky
Last active December 6, 2018 18:07
Show Gist options
  • Save frikky/2aeb61aaf5c23eabd06296e12c99fcfe to your computer and use it in GitHub Desktop.
Save frikky/2aeb61aaf5c23eabd06296e12c99fcfe to your computer and use it in GitHub Desktop.
A post request example for blog
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