I am trying to create a mud (multi user dungeon) client using Electron and ReactJS for myself for learning and challenging myself. But it seems I failed on this challenge.
I am using telnet-stream to get the data from server.
The data from the server has ansi codes since it's a telnet based communication.
The problem is the speed. I am not sure if I am doing it right but here is the component that is responsible for displaying data:
import React, { Component } from 'react';
import styles from './style.css';
type Props = {
output: Array<any>
};
export default class ActionWindow extends Component<Props> {
props: Props;
componentDidMount() {
this.scrollToBottom();
}
componentDidUpdate() {
this.scrollToBottom();
}
scrollToBottom() {
this.el.scrollIntoView({ behavior: 'smooth' });
}
render() {
const output = this.props.output.map(chunk => chunk
.replace('&', '&')
.replace('<', '<')
.replace('>', '>')
.replace(/\x1b\[(\d+);(\d+);?(\d+)?m/g, '</span><span class="c-$1 c-$2 x-$3">')
);
return (
<div className={styles.actionWindowWrapper}>
<span dangerouslySetInnerHTML={{ __html: output }} />
<div ref={el => { this.el = el; }} />
</div>
);
}
}
Is this the correct way, or there is a faster method? The data comes from the main App component by props.