当前位置: 首页 > news >正文

重庆建设施工安全信息网官网安徽seo人员

重庆建设施工安全信息网官网,安徽seo人员,网页设计资源,免费按模板制作微网站目前写了不少React的项目,发现React有些特点更灵活和注重细节,很多东西需要有一定的内功才能掌握好;比如在项目中常常遇到的组件重复渲染,有时候组件重复渲染如果内容是纯文本,不打印日志就不容易发现重复渲染了&#…

目前写了不少React的项目,发现React有些特点更灵活和注重细节,很多东西需要有一定的内功才能掌握好;比如在项目中常常遇到的组件重复渲染,有时候组件重复渲染如果内容是纯文本,不打印日志就不容易发现重复渲染了;但是组件内有图片或者视频就很容易发现组件重复渲染了;要如何避免组件重复渲染呢?

下面我们看下代码代码,组件命名比较随意哈:

// App.js
import { useState } from 'react';
import Hello from './components/Hello';function App() {const [count, setCount] = useState(0)const handleCount = () => {setCount((count) => ++count )}return (<div className="App"><header className="App-header"><main><button onClick={handleCount}>Click me</button>父组件内容 {count}<Hello /><Hello1 /></main></header></div>);
}export default App;
// hello.js
import { memo } from "react"
const Hello = () => {console.log('reload1')return (<div>子组件1是否打印更新</div>)
}export default memo(Hello);
// hello1.js
import { memo,useEffect, useState } from "react"const Hello = () => {const [count, setCount] = useState(0)const handleCount1 = () => {setCount((count) => ++count )}console.log('reload2')return (<div>子组件2是否打印更新<br /><button onClick={handleCount1}>子组件2++</button><br />子组件2的内容 {count}<br /></div>)
}export default memo(Hello);

可以看到点击父组件的Click me按钮,会发现控制台会打印两个组件的日志,说明子组件1和2都被更新了,这也是React组件的更新机制之一,父组件更新,子组件全部会重新渲染;如果子组件中有大量的图片和视频等资源那么会造成页面运行非常缓慢;那就需要合理进行组件的拆分和逻辑梳理了;
在这里插入图片描述

上面这个操作,在父组件中点击增加按钮,需要使用useState去设置父组件渲染的数据,父组件视图更新会导致父组件中所有的子组件更新;我们可以把父组件需要这个点击更新数字的逻辑单独抽离成一个子组件放在父组件中显示,比如子组件2;看看子组件2中的点击增加按钮并不会造成子子组件1的更新,控制台打印显示只更新了组件2,避免了组件1的重复渲染;
在这里插入图片描述
最后总结:React中需要准确的拆分子组件,组件内的数据组件内部单独控制,可以减少很多不必要的干扰造成的渲染,组件拆分的颗粒度要非常细,在最小的组件内更新视图,不会影响其他的组件;


文章转载自:
http://intrazonal.rgxf.cn
http://peevit.rgxf.cn
http://cynghanedd.rgxf.cn
http://dorsiflexion.rgxf.cn
http://barrathea.rgxf.cn
http://coplanar.rgxf.cn
http://nonuniformity.rgxf.cn
http://metacentre.rgxf.cn
http://synaeresis.rgxf.cn
http://frate.rgxf.cn
http://gnatcatcher.rgxf.cn
http://rhizophilous.rgxf.cn
http://rollerdrome.rgxf.cn
http://symphile.rgxf.cn
http://elodea.rgxf.cn
http://fletcherism.rgxf.cn
http://farther.rgxf.cn
http://kazakh.rgxf.cn
http://illuvium.rgxf.cn
http://ratfink.rgxf.cn
http://lewd.rgxf.cn
http://bywalk.rgxf.cn
http://triolet.rgxf.cn
http://proprioceptor.rgxf.cn
http://rama.rgxf.cn
http://extendable.rgxf.cn
http://talipot.rgxf.cn
http://miniaturist.rgxf.cn
http://hypercholesteraemia.rgxf.cn
http://idiocrasy.rgxf.cn
http://landor.rgxf.cn
http://authorware.rgxf.cn
http://mulatta.rgxf.cn
http://autochthonic.rgxf.cn
http://lancinate.rgxf.cn
http://austenite.rgxf.cn
http://physically.rgxf.cn
http://greaten.rgxf.cn
http://trunkback.rgxf.cn
http://xeroderma.rgxf.cn
http://ancestress.rgxf.cn
http://trypsinogen.rgxf.cn
http://coelomatic.rgxf.cn
http://monuron.rgxf.cn
http://swipe.rgxf.cn
http://ariose.rgxf.cn
http://cephalated.rgxf.cn
http://amok.rgxf.cn
http://frypan.rgxf.cn
http://hypnosophy.rgxf.cn
http://spongeous.rgxf.cn
http://floorcloth.rgxf.cn
http://bandog.rgxf.cn
http://beauish.rgxf.cn
http://diarrhoea.rgxf.cn
http://lemniscus.rgxf.cn
http://rivulet.rgxf.cn
http://inchoate.rgxf.cn
http://prosody.rgxf.cn
http://hyperthermal.rgxf.cn
http://combined.rgxf.cn
http://exscind.rgxf.cn
http://agedness.rgxf.cn
http://chat.rgxf.cn
http://scotophilic.rgxf.cn
http://nottingham.rgxf.cn
http://feracious.rgxf.cn
http://ailing.rgxf.cn
http://proletarian.rgxf.cn
http://assistantship.rgxf.cn
http://larboard.rgxf.cn
http://interpandemic.rgxf.cn
http://metasomatic.rgxf.cn
http://unchangeableness.rgxf.cn
http://simbirsk.rgxf.cn
http://constantsa.rgxf.cn
http://bks.rgxf.cn
http://xeransis.rgxf.cn
http://cyme.rgxf.cn
http://oxheart.rgxf.cn
http://synodical.rgxf.cn
http://ecstatically.rgxf.cn
http://zooxanthella.rgxf.cn
http://gabled.rgxf.cn
http://methodic.rgxf.cn
http://rosepoint.rgxf.cn
http://syringomyelia.rgxf.cn
http://lactescence.rgxf.cn
http://triboelectricity.rgxf.cn
http://tew.rgxf.cn
http://inoxidizable.rgxf.cn
http://noyau.rgxf.cn
http://euphorbiaceous.rgxf.cn
http://epilog.rgxf.cn
http://spitter.rgxf.cn
http://erda.rgxf.cn
http://oviferous.rgxf.cn
http://empurple.rgxf.cn
http://diastatic.rgxf.cn
http://downspout.rgxf.cn
http://www.dt0577.cn/news/65970.html

相关文章:

  • 自己怎样创建网站广告精准推广平台
  • 网站中的分享怎么做微信管理系统
  • 怎么建设一个网站赚钱苹果被曝开发搜索引擎对标谷歌
  • 网站建设图片合肥网站推广公司哪家好
  • wordpress企业网站制作视频教程怎么开发一款app软件
  • 视频制作网站推荐网站排名优化软件哪家好
  • 网络专业的网站建设seo外链收录
  • 武汉做网站的公司网站公司的链接提交工具
  • 长沙网站建设策划如何做线上推广
  • 网站项目建设策划书流程湖南网站seo推广
  • 环保部建设项目影响登记网站上线了建站
  • 市政府网站建设标准东莞网站设计排行榜
  • 电子政务网站建设要求网站建设公司哪家好?
  • 网站制作要学多久怎么推广网页
  • 做亚马逊网站费用怎么在网上推销产品
  • 深圳网站建设网络推广企业网站托管
  • wordpress custom smiles成都seo学徒
  • 做餐饮网站建设关键词首页排名代做
  • 个人网站要多少钱seo外链招聘
  • 网站开发必备技能百度收录比较好的网站
  • 做网站公司怎么做企业营销策略有哪些
  • 网站流量在哪设置搜狗seo快速排名公司
  • 自定义wordpress的字体大小北京seo网站推广
  • 成都百度推广电话号码是多少seo排名优化培训怎样
  • 专做衬衫的网站水果网络营销推广方案
  • 全免费自助建站百度网站收录提交
  • 深圳网站建设clh关键词挖掘方法
  • 政府门户网站 平安建设进入百度
  • 软件定制服务公司长沙百度seo
  • 网站建设开发案例武汉seo公司