Skip to content

Instantly share code, notes, and snippets.

@dmi3coder
Last active May 31, 2020 14:11
Show Gist options
  • Save dmi3coder/d8e03cbdfa48d828a5dcc3612f1b9bd7 to your computer and use it in GitHub Desktop.
Save dmi3coder/d8e03cbdfa48d828a5dcc3612f1b9bd7 to your computer and use it in GitHub Desktop.
Example of App.js that uses Swagger endpoints
import React, {useEffect, useState} from 'react';
import './App.css';
import Networking from "./Networking";
import Job from "./Job";
function App() {
const [jobs, setJobs] = useState(null);
const [newJobContent, setNewJobContent] = useState("");
const loadJobs = () => {
Networking.exec({
endpoint: client => client.apis.default.getPosts,
success: result => {
setJobs(result.body)
}
})
}
useEffect(() => {
loadJobs()
}, [])
const submitNewJob = () => {
Networking.exec({
endpoint: client => client.apis.default.post_posts,
data: {requestBody: {"description": newJobContent, "title": newJobContent}},
success: result => loadJobs()
})
}
return (
<div className="App">
<div className="App-header" style={{padding: '3vh'}}>
<h1>Job posts</h1>
{jobs && jobs.map(it => <Job job={it}/>)}
<h2>Create new job</h2>
<input onChange={(e) => setNewJobContent(e.target.value)}/>
<button onClick={submitNewJob}>Submit Job</button>
</div>
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment