Skip to content

Instantly share code, notes, and snippets.

@ayoisaiah
Last active January 20, 2020 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayoisaiah/27d990427db70af40a6868e1083dae5a to your computer and use it in GitHub Desktop.
Save ayoisaiah/27d990427db70af40a6868e1083dae5a to your computer and use it in GitHub Desktop.
// src/pages/Home.tsx
import React, { useState } from 'react';
import axios from 'axios';
import Auth from './Auth';
function useInput(type: string) {
const [value, setValue] = useState('');
const input = (
<input
className="input"
value={value}
onChange={e => setValue(e.target.value)}
type={type}
/>
);
return [value, input];
}
function App() {
const [auth, setAuth] = useState('login');
const [firstName, firstNameInput] = useInput('text');
const [lastName, lastNameInput] = useInput('text');
const [email, emailInput] = useInput('text');
const [password, passwordInput] = useInput('password');
async function login() {
const payload = {
name: {
first: firstName,
last: lastName,
},
email: email,
password: password,
};
try {
const response = await axios.post(
'http://localhost:8080/v1/auth/init',
payload
);
console.log(response.data)
} catch (err) {
console.log(err);
}
}
return (
<Auth
auth={auth}
setAuth={setAuth}
firstNameInput={firstNameInput}
lastNameInput={lastNameInput}
emailInput={emailInput}
passwordInput={passwordInput}
login={login}
/>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment