0

I am using RxJs to create data stream observable. It sends 400 entries after some interval. I am subscribing to it in other react component,

constructor(props) {
        super(props);
        this.state = {data : []};
    }
    componentDidMount() {
        mock.subscribe(val => {
            var data = this.state.data;
            data[val.id] = val;
            this.setState({data: data});
        });
    }

I am facing one issue here, when entries come through observable, it takes time to copy those in react state and then to display the updated data(almost all rows in table) and till that time app becomes slow (sometimes freeze).

What is the better way to subscribe to observable to avoid time delay?

Thanks

Mangesh Tak
  • 346
  • 1
  • 6
  • 22
  • I suggest you to use WebWorker in your application. Please refer the link - https://levelup.gitconnected.com/react-and-web-workers-c9b60b4b6ae8 – Durgesh Pal Jul 04 '20 at 10:14
  • if you can use `reactive-hooks` library - then `useRxState` is the hook you are looking for. See https://itnext.io/hitchhikers-guide-to-reactive-hooks-92c1a708ccfe – c69 Jul 07 '20 at 13:32

0 Answers0