import React, { Component } from 'react'; import formatBytes from './format-bytes' export default class TorrentsStatistic extends Component { constructor(props) { super(props) this.stats = props.stats || {} } componentDidMount() { this.newTorrentFunc = (torrent) => { this.stats.size += torrent.size; this.stats.torrents++; this.stats.files += torrent.files; this.forceUpdate() } window.torrentSocket.on('newTorrent', this.newTorrentFunc); } componentWillUnmount() { if(this.newTorrentFunc) window.torrentSocket.off('newTorrent', this.newTorrentFunc); } render() { return (