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

大型网站建设兴田德润赞扬直播平台推荐

大型网站建设兴田德润赞扬,直播平台推荐,服务平台是什么意思,做网站工作室找客户难结论#xff1a; 16 hooks版本 默认render1次 同步中#xff0c;无论多少种类还是次数#xff0c;都render 1次。 异步中#xff0c;无论多少种类还是次数#xff0c;1个种类执行1次#xff0c;多次的话#xff0c;用n*2。 18 hooks版本 默认render2次#xff0c; 同步…结论 16 hooks版本 默认render1次 同步中无论多少种类还是次数都render 1次。 异步中无论多少种类还是次数1个种类执行1次多次的话用n*2。 18 hooks版本 默认render2次 同步中无论多少种类还是次数都render 2次。 异步中无论多少种类还是次数都render 2次。 15版本, class版本 this.setState是异步的set 3次就会合并在callback可以获取最新值 但是在setTimeout同步的。(set 3次就会执行三次) 15 class版本看这个地址 react18 import React, { useState, useEffect } from react; // 最新的react 16 function Test() {console.log(----render) // 默认执行2次const [countA, setCountA] useState(111);const [countB, setCountB] useState(222);function onClick() {// 一个种类一个set执行2次render// 二个种类各一次set,那么执行2次render// 二个种类及以上执行2次render还是执行2次setCountA(countA 1)// setCountA(countA 1)// setCountA(countA 1)// setCountA(countA 1)// setCountB(countB 1)// setCountB(countB 1)// setCountB(countB 1)// setCountB(countB 1)setTimeout(() {// 一个种类一个set执行2次render// 二个种类各一次set,那么执行2次render// 二个种类及以上执行2次render还是执行2次// setCountA(countA 1)// setCountA(countA 1)// setCountA(countA 1)// setCountA(countA 1)// setCountB(countB 1)// setCountB(countB 1)// setCountB(countB 1)// setCountB(countB 1)});}useEffect(() {}, []);return (divp{countA}-{countB}/pbutton onClick{onClick}点击我/button/div) } export default Test;react16 import React, { useState, useEffect } from react; // 最新的react 16 function Test() {console.log(--render) // 默认执行1次const [countA, setCountA] useState(111);const [countB, setCountB] useState(222);function onClick() {// 一个种类一个set执行1次render// 二个种类各一次set,那么执行1次render// 二个种类及以上执行2次render还是执行1次// setCountA(countA 1)// setCountA(countA 1)// setCountA(countA 1)// setCountA(countA 1)// setCountB(countB 1)// setCountB(countB 1)// setCountB(countB 1)// setCountB(countB 1)setTimeout(() {// 一个种类一个set执行1次render// 二个种类各一次set,那么执行2次render// 二个种类及以上n执行2次render及以上n*2setCountA(countA 1)setCountA(countA 1)setCountA(countA 1)setCountA(countA 1)setCountB(countB 1)setCountB(countB 1)setCountB(countB 1)setCountB(countB 1)});}useEffect(() {}, []);return (divp{countA}-{countB}/pbutton onClick{onClick}点击我/button/div) } export default Test;react16, 18 import React, { useState } from react;function App() {const [number, setNumber] useState(0);function alertNumber() {setTimeout(() {alert(number); // 操作步骤先点击弹窗然后快速按钮永远弹出的是016和18都这样子}, 3000);}return (div classNameAppp{number}/pbutton onClick{() setNumber(number 1)}/buttonbutton onClick{alertNumber}alertNumber/button/div); } export default App;一下的以前的博客不可靠 react刷新几次问题 15版本, class版本 this.setState是异步的set 3次就会合并在callback可以获取最新值 但是在setTimeout同步的。(set 3次就会执行三次) 15 class版本看这个地址 16版本hooks版本 setState set几次就会render几次但是有惰性。不会批处理。 18版本 批处理了。异步。可以调用同步的api。 setTimeout中的也可以批处理了。 legacy模式下命中batchedUpdates时是异步 未命中batchedUpdates时是同步的 concurrent模式下都是异步的,react 17添加了这个concurrent模式 react 16 setTimeout异步中的setA不可控制 useState会对state进行逐个处理useState的原理是用闭包机制而setTimeout中任务是无法拿到闭包中的变量的所以当遇到 setTimeout时在setTimeout拿不到最新的值。 setState会进行一个合对象的则只会处理最后一次。 当遇到 setTimeout/setInterval/Promise.then(fn)/fetch 回调/xhr 网络回调时react 都是无法控制的,这个根react本身的原因有关系。 react 18 中对setTimeout中连续两次的setA也进行了合并不知道18中setTimeout可不可以控制。 const [a, setA] useState(123); console.log(----render); return (div classNameApph1{a}/h1button onClick{() {// react 16 刷新两次, 结果仍然为124 react18刷新一次setA(a1);setA(a1);}}fffff/button/div ); ---------------------------------------- const [number,setNumber] useState(0); function alertNumber(){setTimeout((){alert(number); // 不论您点击多少次下边的click这里就是0},3000); } return (p{number}/pbutton onClick{()setNumber(number1)}/buttonbutton onClick{alertNumber}alertNumber/button/ ) ---------------------------------------- export default function App() {console.log(render----);const [ca, setCa] useState(1);const aclick () {setTimeout(() {// 会执行两次但是最后的结果只会1setCa(ca 1);setCa(ca 1);});}return (div classNameApp onClick{aclick}{ca}/div); }
http://www.hkea.cn/news/14408099/

相关文章:

  • 网站建设责任分工永年网站制作
  • 让别人做一个网站需要多少钱手机网址打不开怎么解决
  • asp在网站开发中的作用企业建网站群
  • 网站建设dw 什么软件建网站定制
  • 网站自己做流量湛江网站网站建设
  • 惠州附近做商城网站建设哪家好中国菲律宾签证
  • 互联网保险论文企业网站搜索引擎优化方案
  • 青浦华新网站建设深圳网络推广公司有哪些
  • 网站的宣传推广包括dw个人简历网页制作
  • 网站敏感词汇个人养老保险缴费标准
  • 聚美优品网站建设导向图灵机器人 wordpress
  • 英语培训东莞网站建设哪个网站空间好
  • 如何申请网站合肥网站建设哪个公司做得比较好
  • 网站建设分前端和后台吗安阳门户网站
  • 有经验的企业网站建设访问网站的过程
  • 宁波网站seo苏格网站建设
  • 我想注册网站怎么做网站定制设计制作公司
  • 手机微网站开发教程微信安装到手机
  • 高新区建设局网站如皋做网站的
  • 合肥微网站建设汕头网站建设搭建
  • 东莞网站建设 石佳汽车设计网站
  • 门户网站的功能微信公众号运营一年多少钱
  • 厦门无忧网站建设有限公司网站怎么对接微信支付宝
  • 贵州省住房和城乡建设官方网站wordpress 顶部公告
  • 网站及app开发建设网站需要购买虚拟主机吗
  • 青岛做网站优化哪家好有意思的网站
  • 三合一网站模板网站权重优化方式
  • 网站管家邳州网站
  • php语言做的大网站网页制作全部过程
  • 互联网装修公司加盟优化网站的公司哪家好