Skip to content

Instantly share code, notes, and snippets.

@lakshaygupta21
Created September 19, 2020 09:08
Show Gist options
  • Save lakshaygupta21/9b3b7aad6b83c570636fd143eeb23c18 to your computer and use it in GitHub Desktop.
Save lakshaygupta21/9b3b7aad6b83c570636fd143eeb23c18 to your computer and use it in GitHub Desktop.
import React,{useEffect, useState} from 'react';
import logo from './logo.svg';
import axios from 'axios'
import './App.css';
function App() {
const[data,setData] = useState({
flag:false,
result:''
})
const[predicted,setPredicted] = useState([])
useEffect(()=>{
async function tablePredicted(){
const res = await axios.get(`http://localhost:3001/predicted`)
if(res.data)
setPredicted(res.data)
}
tablePredicted()
},[])
const{result,flag} = data;
async function predict(par){
setData({
...data,
flag:true
})
const response = await axios.get(`http://localhost:3001/${par}`)
setData({
...data,
flag:false,
result:response.data.result
})
console.log(result)
}
return (
<React.Fragment>
<div style={{textAlign:'center',fontSize:'larger'}}>Check the value of 1 USD after <input type = "number" onChange={(e)=>{
predict(e.target.value)
console.log(e.target.value)
}}></input> days in INR</div>
<div style={{textAlign:'center', fontSize:'10rem'}}>
{!flag && <div><i class="fa fa-inr" aria-hidden="true"></i>{result}</div> }
</div>
<React.Fragment>
</React.Fragment>
{predicted.length &&
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Predicted</th>
<th>Actual</th>
</tr>
</thead>
<tbody>
{predicted.map((result)=>(
<tr>
<td>{result.Date}</td>
<td>{result.predicted}</td>
<td>{result.actual}</td>
</tr>
))}
</tbody>
</table>}
</React.Fragment>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment