import React from "react" import { Component } from "react" import Plot from "react-plotly.js" import { NewTickData, socket } from '../'; type FirstConnectData = { ticks: Array, prices: Array } type PlotState = { x: Array, y: Array } class RPlot extends Component<{}, PlotState> { constructor(props) { super(props) } state = { x: [], y: [] } componentDidMount() { socket.on("first_connect", (data: FirstConnectData) => { this.setState({ x: data.ticks, y: data.prices }) }) socket.on("new_tick", (data: NewTickData) => { this.setState({ x: [...this.state.x, data.tick], y: [...this.state.y, data.price], }) }) } render() { return ( ) } } export default RPlot;