1
テキストエリアにテキストを差し向けて、最後までスクロールして最新のビューを保持します。しかし、これを実行すると、ブラウザがクラッシュしたり、メモリが不足しているように見えます。誰もこのコードを最適化するのに役立つことができますReactテキストエリアの一番下までスクロール
//Appending text and calling scroll function
this.setState({ transcriptText: this.state.transcriptText + resp.log })
this.scrollToBottom();
//Textarea
<TextArea
ref={textLog => this.textLog = textLog}
autosize={{ minRows: 10, maxRows: 15 }}
value={this.state.transcriptText}
>
</TextArea>
//Scrolling
scrollToBottom =() => {
const textLogContainer = ReactDOM.findDOMNode(this.textLog);
if(textLogContainer){
textLogContainer.scrollTop = textLogContainer.scrollHeight;
}
};
全
componentDidMount() {
const socket = io.connect(process.env.REACT_APP_API_URL, { transports: ['websocket'] });
socket.emit('onboarding', { id: uploadId });
socket.on('transcript_log', function (resp) {
this.setState({ transcriptText: this.state.transcriptText + resp.log })
this.scrollToBottom();
}.bind(this));
}
あなただけrefがnullであるかどうかを確認してからscrollTop
を変更するためにそれを変更、あなたが参照を持っているときReactDOM.findDOMNode
を行う必要はありませんおかげ
何も同様
。 – Chris
これはthis.textLog.scrollTop = this.textLog.scrollHeightですか?私はDOMの行を削除すると、textLogContainerは存在しません? –
あなたはおそらく正しいでしょう。私は多くのアプリでフローを使用していますが、refを使用する前にこれを行う必要がありますが、それがなければおそらく警告は表示されません。 – Dakota