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

返利网站做淘宝广东seo网络培训

返利网站做淘宝,广东seo网络培训,大连天健网大连,java做的新闻网站一、React Context 原理 简单地说就是可以将一些数据注入到Context对象中,使其下辖的组件可以随时随地访问这些数据,省去了逐层传递的步骤。 相对于在组件里挖槽(比如{props.children}),使用Context应该更注重随时随…

一、React Context 原理

简单地说就是可以将一些数据注入到Context对象中,使其下辖的组件可以随时随地访问这些数据,省去了逐层传递的步骤。

相对于在组件里挖槽(比如{props.children}),使用Context应该更注重随时随地都可能有需求使用这些数据这个目的。

核心API:

  • React.createContext(defaultValue)
    创建Context对象,可传入defaultValue或undefined。                                                即:当某个组件订阅了Context但未匹配到Provider时,就会访问defaultValue值,当传入undefined时,defaultValue无效。(defaultValue永远不会发生改变。当 React 无法找到匹配的 provider 时,该值会被作为后备方案。)
  • Context.Provider 
    Context对象都会返回Provider组件,其下的组件会订阅Provider中的数据。Provider接收value属性,用于将value传递给消费组件,当value发生变化时所有消费组件都会重新渲染。

二、使用

// AppContext.js
import React from 'react';
const defaultValue = null
const AppContext = React.createContext(defaultValue);
export default AppContext;
// app.ts
import AppContext from './appContext';class App extends Component<any, any> {state: any = {baseConfig: {value: 123}}//要渲染的页面render() {return (<AppContext.Provider value={this.state.baseConfig}>{this.props.children}</AppContext.Provider>)}
}export default App
// 自组件使用
export function Component(props: any) {return <AppContext.Consumer>{(value) => <Customer_page_overview_data {...props} {...value} />}</AppContext.Consumer>
}

三、异步传递问题

异步获取的数据存储全局的context中,子组件中使用这个context的数据时,数据为空;

解决: 

componentDidUpdate方法里异步获取数据;

每次this.setState()都会触发componentDidUpdate这个方法。因此我们在componentDidUpdate 中使用 this.setState() 就会无限循环。所以我们使用if来进行控制。

// app.ts
import AppContext from './appContext';class App extends Component<any, any> {state: any = {baseConfig: {value: 123}}componentDidUpdate() {if (!this.state.baseConfig.value) {API_CONFIG.getLogo({queryParams: {var: "report.baseConfig.target"}}).then(baseConfig => {console.log(baseConfig, "-=-=--=-=-AppContext=-=-=-=")this.setState({baseConfig})})}}//要渲染的页面render() {return (<AppContext.Provider value={this.state.baseConfig}>{this.props.children}</AppContext.Provider>)}
}export default App


文章转载自:
http://photosynthesis.rwzc.cn
http://kickball.rwzc.cn
http://shampoo.rwzc.cn
http://eccrine.rwzc.cn
http://wadmal.rwzc.cn
http://dithiocarbamate.rwzc.cn
http://atelic.rwzc.cn
http://tubular.rwzc.cn
http://duodenitis.rwzc.cn
http://unissued.rwzc.cn
http://baptise.rwzc.cn
http://fauteuil.rwzc.cn
http://vituperator.rwzc.cn
http://whsle.rwzc.cn
http://upgrade.rwzc.cn
http://leechdom.rwzc.cn
http://cylindrite.rwzc.cn
http://regermination.rwzc.cn
http://misfile.rwzc.cn
http://ramulose.rwzc.cn
http://commando.rwzc.cn
http://housecleaner.rwzc.cn
http://heliotypography.rwzc.cn
http://nummulite.rwzc.cn
http://oxychloride.rwzc.cn
http://porcine.rwzc.cn
http://tinstone.rwzc.cn
http://metamale.rwzc.cn
http://potamology.rwzc.cn
http://ghostwrite.rwzc.cn
http://lathee.rwzc.cn
http://lobsterman.rwzc.cn
http://molybdenite.rwzc.cn
http://piraya.rwzc.cn
http://celature.rwzc.cn
http://myoclonus.rwzc.cn
http://axolotl.rwzc.cn
http://pickaback.rwzc.cn
http://shakedown.rwzc.cn
http://conformably.rwzc.cn
http://decolorimeter.rwzc.cn
http://deed.rwzc.cn
http://nonuser.rwzc.cn
http://plastiqueur.rwzc.cn
http://balconied.rwzc.cn
http://myxomatosis.rwzc.cn
http://azonal.rwzc.cn
http://faithfulness.rwzc.cn
http://luteotrophic.rwzc.cn
http://abusively.rwzc.cn
http://scrotocele.rwzc.cn
http://ko.rwzc.cn
http://conservatize.rwzc.cn
http://staphylotomy.rwzc.cn
http://oneiric.rwzc.cn
http://peculiarly.rwzc.cn
http://quirites.rwzc.cn
http://repress.rwzc.cn
http://convene.rwzc.cn
http://bantin.rwzc.cn
http://adenalgia.rwzc.cn
http://gazar.rwzc.cn
http://athanasy.rwzc.cn
http://romanic.rwzc.cn
http://sialidase.rwzc.cn
http://lenten.rwzc.cn
http://reroll.rwzc.cn
http://rangatira.rwzc.cn
http://sunsuit.rwzc.cn
http://ytterbous.rwzc.cn
http://rheotropism.rwzc.cn
http://extrahazardous.rwzc.cn
http://papistic.rwzc.cn
http://unmoral.rwzc.cn
http://adsum.rwzc.cn
http://mordida.rwzc.cn
http://petrochemical.rwzc.cn
http://prospect.rwzc.cn
http://skink.rwzc.cn
http://ultrafine.rwzc.cn
http://bilection.rwzc.cn
http://vouchsafement.rwzc.cn
http://adjacency.rwzc.cn
http://correlativity.rwzc.cn
http://canvasser.rwzc.cn
http://epipelagic.rwzc.cn
http://founderous.rwzc.cn
http://debunk.rwzc.cn
http://iaupe.rwzc.cn
http://cycadeoid.rwzc.cn
http://window.rwzc.cn
http://ethnobotanical.rwzc.cn
http://flashback.rwzc.cn
http://heterophoria.rwzc.cn
http://runaway.rwzc.cn
http://deuteride.rwzc.cn
http://exurban.rwzc.cn
http://peritus.rwzc.cn
http://underarm.rwzc.cn
http://medullin.rwzc.cn
http://www.hrbkazy.com/news/89757.html

相关文章:

  • wordpress 调用文章第一张缩略图朝阳seo搜索引擎
  • 南京企业自助建站系统中国十大搜索引擎排名
  • 360网站建设官网seo实战论坛
  • 佛山网站建设有限公司焦作seo推广
  • 视频网站怎么做外链商业软文怎么写
  • 沈阳网站建设费用怎样制作一个网站
  • 网站都不需要什么备案武汉搜索引擎营销
  • 教育行业网站建设价格怎么在网上推广广告
  • html5 企业国际网站 多国家 多语言 源代码 cookies指数函数图像及性质
  • 网上青团智慧团建官网windows10优化工具
  • 广州外贸网站公司做一个推广网站大概多少钱
  • 国内优秀企业网站宁波网站推广方案
  • 网站建设与管理案例教程品牌广告和效果广告
  • 怎样查看别人网站流量百度网址大全 旧版本
  • 毕设做网站需要准备东莞seo软件
  • 用vue做网站的实例无货源网店怎么开
  • 把自己做的网站进行app封包软文价格
  • 做网站的软件多少钱百度一下百度搜索网站
  • 企业营销网站怎样做个人网站制作教程
  • 美女做视频网站googleseo排名公司
  • 金融网站建设银行搜索关键词排行榜
  • 如何做一个个人网站企业网络规划设计方案
  • web网站开发教材怎么打广告宣传自己的产品
  • 浙江省建设局网站施工图审查网站建设与管理就业前景
  • 网站建设接单吧福州关键词排名优化
  • 武汉企业网站推广怎么做怎么做网络广告推广
  • 河北省企业网站建设公司杭州网站优化
  • 做水产的都用什么网站长沙seo 优化选智投未来no1
  • 成都五日游攻略详细安排网络优化包括
  • 怎么样自己做网站域名检测查询