栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

ReactJS中的非阻塞渲染

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ReactJS中的非阻塞渲染

这是一个很大的问题,也是一个理想的用例

setTimeout
,可以为该事件安排下一个事件循环的更新。

与其存储要渲染的组件数量,不如存储一个组件数组并直接渲染它们。
jsfiddle

 var CommentBox = React.createClass({    getInitialState: function() {      return { boxes: [<Box key="first" />] };    },    heavyLoadRender: function() {      setTimeout(() => {        if (this.state.boxes.length < 50000) {          this.setState({  boxes: this.state.boxes.concat(<Box key={this.state.boxes.length} />)          })          this.heavyLoadRender()        }      })    },    render: function() {      return (        <div>          <button onClick={this.heavyLoadRender}>Start</button>          {this.state.boxes}        </div>      )    }  })

更新:

如果只想在阵列填满后显示状态,则在达到该大小之前不显示任何内容:

这不起作用:

{ this.state.boxes.length === 50000 && this.state.boxes }

希望并没有失去!使用风格!

<div style={{ display: this.state.boxes.length === 50000 ? 'block' : 'none' }}>  { this.state.boxes }</div>

如果要提高速度,则可以按

setTimeout

var newBoxes = []for (var i = 0; i < 5; i++) {   newBoxes.push(<Box />)}this.setState({   boxes: this.state.boxes.concat(newBoxes)})

更新小提琴。我认为整个问题类别都需要花费一些时间来执行。在10,000个批次中,基本的包装盒组件不会阻塞,您可以轻松地将装载微调器扔到那里。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/398028.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号