adding redirecting to room and saving id

This commit is contained in:
Wenszel
2021-03-15 20:50:19 +01:00
parent 6ffc7fb3b8
commit 47dc0848ca
8 changed files with 353 additions and 9 deletions
+11 -3
View File
@@ -1,10 +1,18 @@
import React, { useState } from 'react';
import { BrowserRouter as Router , Redirect } from 'react-router-dom';
import NameInput from './components/NameInput';
function App() {
const [id, setId] = useState('')
const [redirect, setRedirect] = useState(false)
const idCallback = (id)=>{
setId(id);
setRedirect(true);
}
return (
<div>
<NameInput />
</div>
<Router>
{redirect ? <Redirect to="/game"></Redirect> : <NameInput idCallback = {idCallback}/>}
</Router>
);
}
+4 -1
View File
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import axios from 'axios';
const NameInput = () => {
const NameInput = ({ idCallback }) => {
const [inputValue, setInputValue] = useState('');
const handleInputChange = (e) => {
setInputValue(e.target.value);
@@ -13,6 +13,9 @@ const NameInput = () => {
},{
"Content-Type": "application/json"
})
.then(response => {
idCallback(response.data.id);
})
}
return(
<div>