adding redirecting to room and saving id
This commit is contained in:
+11
-3
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user