19 lines
582 B
JavaScript
19 lines
582 B
JavaScript
|
import React from "react";
|
||
|
|
||
|
class MainBody extends React.Component {
|
||
|
render() {
|
||
|
const requestOptions = {
|
||
|
method: 'POST',
|
||
|
headers: { 'Content-Type': 'application/json' },
|
||
|
body: JSON.stringify({ title: 'React POST Request Example' })
|
||
|
};
|
||
|
fetch('https://jsonplaceholder.typicode.com/posts', requestOptions)
|
||
|
.then(response => response.json())
|
||
|
.then(data => this.setState({ postId: data.id }));
|
||
|
return (
|
||
|
<div>Hey from other class</div>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default MainBody;
|