From 2f6aa949434a1ce1220514d57828709ac705f6cc Mon Sep 17 00:00:00 2001 From: Pushkaraj12 <93024602+Pushkaraj12@users.noreply.github.com> Date: Thu, 2 Mar 2023 11:03:41 +0530 Subject: [PATCH] Update App.tsx --- src/App.tsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 0728518c0d8..92ed567c9de 100755 --- a/src/App.tsx +++ b/src/App.tsx @@ -8,6 +8,7 @@ import './App.css'; */ interface IState { data: ServerRespond[], + showGraph: boolean, } /** @@ -22,6 +23,7 @@ class App extends Component<{}, IState> { // data saves the server responds. // We use this state to parse data down to the child element (Graph) as element property data: [], + showGraph: false, }; } @@ -29,18 +31,30 @@ class App extends Component<{}, IState> { * Render Graph react component with state.data parse as property data */ renderGraph() { - return () + if(this.state.showGraph) { + return () + } } + /** * Get new data from server and update the state with the new data */ getDataFromServer() { + let x = 0; + const interval = setInterval(() => { DataStreamer.getData((serverResponds: ServerRespond[]) => { - // Update the state by creating a new array of data that consists of - // Previous data in the state and the new data from server - this.setState({ data: [...this.state.data, ...serverResponds] }); + this.setState({ + data: serverResponds, + showGraph: true, + }); + }); + x++; + if( x > 1000 ) { + clearInterval(interval); + } + }, 100) } /**