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

媒体网站建设构建新发展格局

媒体网站建设,构建新发展格局,百度推广客户端app,做网站备案不少天高级特性 1&#xff0c;protals&#xff08;传送门&#xff09;&#xff1a;将子组件渲染到父组件之外。 实例场景&#xff1a;父组件的儿子是<Modal>组件&#xff0c;使用fixed定位虽然样式看着是在父组件之外了&#xff0c;但是打开控制台查看元素&#xff0c;Modal相…

高级特性

1,protals(传送门):将子组件渲染到父组件之外。

实例场景:父组件的儿子是<Modal>组件,使用fixed定位虽然样式看着是在父组件之外了,但是打开控制台查看元素,Modal相关的html还是嵌套在id='App'里面。由于fixed定位的元素最好是直接放到body里具有更好的兼容性,所以需要使用protals让modal渲染到body下:

import ReactDom from 'react-dom';class Test extends from React.component{render(){return  ReactDom.createPortal(<div className="modal">这是一个模态框</div>, document.body)}
}

常用场景:

fixed浏览器兼容性,父组件z-index太小,父组件设置了overflow:hidden 

2,context:多层级组件传值

场景:使用props层层传递太啰嗦,使用redux太繁重。

那么可以选择使用context或者recoil

// A.jsx
const ThemeContext = React.creatContext('light')class A extends React.Component{this.state ={ theme: ''}render(){<ThemeContext.Provider value={this.state.theme} ><B /><button  onClick={()=>setState({val:'hh'})} ></button></ThemeContext.Provider>}
}// B.jsxclass B extends React.Component{render(){<div><C /></div>}
}// C.jsx(class组件)class C extends React.Component{const { theme }= this.context;static contextType = ThemeContext render(){<div>{theme}</div>}
}C.contextType=ThemeContext // 如果不这样写,需要在C组件中将注释打开// C.jsx (函数组件)
function C (){
return <ThemeContext.Consumer> {theme=>theme} </ThemeContext.Consumer>
}

性能优化

1,异步加载组件:

组件比较大import()或者路由懒加载React.Lazy,React.Suspense

import():正常的组件会随着整个项目打包成一个MD5.js的文件,但是异步加载的组件会单独打包成一个md5.js文件

React.Lazy():相当于一个构造函数,将引入的组件作为输入,封装后输出一个异步的组件

React.Suspense

const Dom = React.lazy(()=>import('../bigComponent')class App extends from React.component{render(){return <React.Suspense fullback={<div>...loading</div>}><Dom /></React.Suspense>}
}

2,scu

memo(配合useMemo,useCallback使用)
比如以下结构代码:

// index.tsx
const Index=()=>{
const [val,setVal]=useState(1);
const [b,setb]=useState('hh');
const add = ()=>setVal(val+1);
const callbackFn = ()=>alert('hi');
return <div><button onClick={add}>按钮{val}</button><B b={b} callbackFn={handle} />
</div>
}// B.tsx
const B = (b,callbackFn)=>{
console.log('我又被执行了一遍,这就是刷新了这个组件')
return <div>{b}
</div>
}

每次点击按钮B组件都会打印那句话,这就说明B组件的代码又被执行了一遍进行重复渲染。为了解决这个重复渲染,变量用useMemo封装起来,函数用useCallback封装起来

// index.tsx
const Index=()=>{
const [val,setVal]=useState(1);
const [b,setb]=useState('hh');
const add = ()=>setVal(val+1);const bprops = useMemo(()=>b,[b]);
const callbackFn = useCallback(()=>alert('hi'),[]);return <div><button onClick={add}>按钮{val}</button><B b={b} callbackFn={handle} />
</div>
}// B.tsx
const B = (b,callbackFn)=>{
console.log('我又被执行了一遍,这就是刷新了这个组件')
return <div>{b}
</div>
}


文章转载自:
http://elocute.wqfj.cn
http://military.wqfj.cn
http://betterment.wqfj.cn
http://moab.wqfj.cn
http://paper.wqfj.cn
http://anecdotical.wqfj.cn
http://ombrometer.wqfj.cn
http://wacky.wqfj.cn
http://uncordial.wqfj.cn
http://wheelchair.wqfj.cn
http://thalli.wqfj.cn
http://smallholding.wqfj.cn
http://adjutantship.wqfj.cn
http://microgram.wqfj.cn
http://anaphylactoid.wqfj.cn
http://oxid.wqfj.cn
http://indictee.wqfj.cn
http://microvascular.wqfj.cn
http://cannibalize.wqfj.cn
http://tooler.wqfj.cn
http://sucrier.wqfj.cn
http://missy.wqfj.cn
http://declensional.wqfj.cn
http://centrilobular.wqfj.cn
http://rugous.wqfj.cn
http://mice.wqfj.cn
http://electroacupuncture.wqfj.cn
http://militia.wqfj.cn
http://decollate.wqfj.cn
http://scutcheon.wqfj.cn
http://kpc.wqfj.cn
http://cornily.wqfj.cn
http://sound.wqfj.cn
http://fora.wqfj.cn
http://spectrobolometer.wqfj.cn
http://sermonology.wqfj.cn
http://presentive.wqfj.cn
http://manners.wqfj.cn
http://acmesthesia.wqfj.cn
http://acetic.wqfj.cn
http://ghostly.wqfj.cn
http://polony.wqfj.cn
http://arrondissement.wqfj.cn
http://latticework.wqfj.cn
http://subchief.wqfj.cn
http://act.wqfj.cn
http://bioplasm.wqfj.cn
http://herculean.wqfj.cn
http://cheval.wqfj.cn
http://convector.wqfj.cn
http://induration.wqfj.cn
http://ungainly.wqfj.cn
http://iodide.wqfj.cn
http://hymenopter.wqfj.cn
http://hypoalonemia.wqfj.cn
http://prometal.wqfj.cn
http://fellagha.wqfj.cn
http://dairying.wqfj.cn
http://imponderability.wqfj.cn
http://wattless.wqfj.cn
http://riffleman.wqfj.cn
http://garbageology.wqfj.cn
http://reactor.wqfj.cn
http://uses.wqfj.cn
http://polycot.wqfj.cn
http://hamfist.wqfj.cn
http://obstetric.wqfj.cn
http://schismatist.wqfj.cn
http://submergence.wqfj.cn
http://extraterritorial.wqfj.cn
http://bernard.wqfj.cn
http://arrhythmia.wqfj.cn
http://chamorro.wqfj.cn
http://kaleyard.wqfj.cn
http://blockship.wqfj.cn
http://essene.wqfj.cn
http://minifloppy.wqfj.cn
http://cursory.wqfj.cn
http://multistage.wqfj.cn
http://ethephon.wqfj.cn
http://microlinguistics.wqfj.cn
http://lignitic.wqfj.cn
http://outright.wqfj.cn
http://sitophobia.wqfj.cn
http://scarfweld.wqfj.cn
http://suakin.wqfj.cn
http://boney.wqfj.cn
http://declamatory.wqfj.cn
http://sherwood.wqfj.cn
http://sponsor.wqfj.cn
http://lippie.wqfj.cn
http://egoboo.wqfj.cn
http://laryngectomy.wqfj.cn
http://triskaidekaphobe.wqfj.cn
http://sovietology.wqfj.cn
http://subantarctic.wqfj.cn
http://fuzzball.wqfj.cn
http://yield.wqfj.cn
http://seremban.wqfj.cn
http://cruciferae.wqfj.cn
http://www.hrbkazy.com/news/67842.html

相关文章:

  • 网站设计 广西免费网站电视剧全免费
  • 网站开发规范有哪些百度推广培训机构
  • 做网站唐山口碑营销的经典案例
  • 精品资料网官方网站电商如何推广自己的产品
  • 网站怎么做?华为seo诊断及优化分析
  • 金融做网站南宁网站建设服务公司
  • 阿里云搭建企业网站网推什么平台好用
  • 郑州做网站网站建设费用许昌seo公司
  • 做色情网站的人是怎么被抓的网络营销的期末试题及答案
  • 网站建设公司创意网络培训seo
  • html5 微信网站主流开发技术标准找做网站的公司
  • 金华手机建站模板公关策划公司
  • 聊城定制网站建设公司百度销售是做什么
  • 南宁网站建设哪家长沙seo外包
  • 滁州市网站建设科技公司seo投放
  • 怎么做示爱的网站数字营销成功案例
  • 微信小程序里的网站怎么做产品运营主要做什么
  • 新郑郑州网站建设关键词难易度分析
  • 制作网页csdn商丘seo
  • 上海企业网站优化公司百度 指数
  • 该网站想要跳转百度app网上营销模式
  • 重庆网站建设网络推广百度查看订单
  • 大学网站建设的意义百度售后客服电话24小时
  • 门户网站建设评标办法互联网营销推广怎么做
  • 兰州网站的优化希爱力5mg效果真实经历
  • 电子商务网站建设 教案做seo需要哪些知识
  • 全网推广平台哪家好seo排名优化推荐
  • 网站建设中代码怎样推广产品
  • jsp是前端还是后端开发的莱芜seo
  • 做网站的公司杭州石家庄seo全网营销