React components render order All In One
React components render order All In One
components render order / components lifecycle
DOM tree render order
React diff
React fiber
当父组件进行重新渲染操作时,即使子组件的props或state没有做出任何改变,也会同样进行重新渲染
当子组件进行重新渲染操作时,只有子组件会同样进行重新渲染

parent component change props
import Parent from "./components/parent";
export default function App() {
const [name, setName] = useState(`xgqfrms`);
const [show, setShow] = useState(true);
const toggleShow = () => {
setShow(!show);
};
const updateName = () => {
setName(`webfullstack`);
};
useEffect(() => {
// Update the document title using the browser API
let flag = true;
if (flag) {
document.title = `react hooks ${show}`;
}
// cancel promise
return () => (flag = false);
}, [show]);
return (
<div className="App">
<h1>react-parent-child-lifecycle-order</h1>
<button onClick={toggleShow}>toggleShow</button>
<p>update props name</p>
<button onClick={updateName}>updateName</button>
{show && <Parent name={name}/>}
</div>
);
}
parent component change state
import React, { Component } from "react";
import Child from "./child";
import log from "../utils/log";
class Parent extends Component {
constructor(props) {
super();
this.state = {
show: true,
randomName: props.name,// "xgqfrms"
};
this.toggleShow = this.toggleShow.bind(this);
log(`parent constructor`, 0);
}
getRandomName = () => {
const randomName = Math.random() > 0.5 ? `abc` : `xyz`;
this.setState({
randomName,
});
};
toggleShow = () => {
const { show } = this.state;
this.setState({
show: !show
});
};
componentWillMount() {
log(`parent WillMount`, 1);
}
// UNSAFE_componentWillMount() {
// log(`parent UNSAFE_WillMount`, 1);
// }
componentDidMount() {
log(`parent DidMount`, 2);
}
componentWillReceiveProps() {
log(`parent WillReceiveProps`, 3);
}
// UNSAFE_componentWillReceiveProps() {
// log(`parent UNSAFE_WillReceiveProps`, 3);
// }
shouldComponentUpdate() {
log(`parent shouldComponentUpdate`, 4);
return true;
// return true or false;
}
componentWillUpdate() {
log(`parent WillUpdate`, 5);
}
// UNSAFE_componentWillUpdate() {
// log(`parent UNSAFE_WillUpdate`, 5);
// }
componentDidUpdate() {
log(`parent DidUpdate`, 6);
}
componentWillUnmount() {
log(`\n\nparent WillUnmount`, 7);
}
componentDidCatch(err) {
log(`parent DidCatch`, err);
}
render() {
log(`parent render`);
const {
show,
randomName,
} = this.state;
return (
<div className="parent">
<h1>parent-lifecycle-order</h1>
<button onClick={this.getRandomName}>get random name</button>
<p>randomName = {randomName}</p>
<button onClick={this.toggleShow}>toggleShow</button>
{show && <Child />}
</div>
);
}
}
export default Parent;
child component change state
demos
https://codesandbox.io/s/react-parent-child-lifecycle-order-update-parent-state-render-render-2559w
refs
https://stackoverflow.com/questions/44654982/in-which-order-are-parent-child-components-rendered
https://scotch.io/courses/getting-started-with-react/parent-child-component-communication
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
React components render order All In One的更多相关文章
- [React] Recompose: Theme React Components Live with Context
SASS Bootstrap allows us to configure theme or branding variables that affect all components (e.g. P ...
- [React] Styling React Components With Aphrodite
Aphrodite is a library styling React components. You get all the benefits of inline styles (encapsul ...
- [React] Extracting Private React Components
we leverage private components to break our render function into more manageable pieces without leak ...
- Rendering React components to the document body
React一个比较好用的功能是其简单的API,一个组件可以简单到一个return了组件结构的render函数.除了一个简单的函数之外,我们还有了一段有用且可复用的代码片段. 问题 不过有时候可能会受到 ...
- React Components Template
React Components Template "use strict"; /** * * @author xgqfrms * @license MIT * @copyrigh ...
- [React] Create and import React components with Markdown using MDXC
In this lesson I demonstrate how to use the library MDXC to create and import React components with ...
- React Components之间的通信方式了解下
先来几个术语: 官方 我的说法 对应代码 React element React元素 let element=<span>A爆了</span> Component 组件 cla ...
- [Poi] Use Markdown as React Components by Adding a Webpack Loader to Poi
Poi ships with many webpack loaders included, but you may run into scenarios where you'll need to cu ...
- [Recompose] Create Stream Behaviors to Push Props in React Components with mapPropsStream
Rather than using Components to push streams into other Components, mapPropsStream allows you to cre ...
随机推荐
- Ubuntu 能ping通DNS 地址 无法解析域名
ping通qq百度都行,唯独谷歌不行, 主机能够ping通google的dns服务器地址 8.8.8.8,却无法解析域名 $ ping www.google.co.uk ping: unknown ...
- 【UltraISO】中文破解版
下载链接:https://cn.ultraiso.net/uiso9_cn.exe简体中文版专用: 注册名:Guanjiu 注册码:A06C-83A7-701D-6CFC多国语言版专用: ...
- 关于jmeter客户端实现中HttpClient4与Java的区别
如上图:jmeter客户端实现方式有三种,一种是java,一种是httpclient4,还有一种默认,我们来看一下java与httpclient4的区别: Java:选择压测时,链接是复用的(代码中的 ...
- 标准PE头属性说明
- Mac下IDEA激活Jrebel
第一步:在idea中下载jrebel,过程省略 第二步:配置反向代理工具 Windows 版:http://blog.lanyus.com/archives/317.html MAC 版: 安装hom ...
- jQuery——样式与动画
通过jQuery,不仅能够轻松地为页面操作添加简单的视觉效果,甚至能创建更精致的动画. ###修改内联CSS jQuery提供了.css()方法. 这个方法集getter(获取方法)和setter(设 ...
- Flink 在又拍云日志批处理中的实践
日前,由又拍云举办的大数据与 AI 技术实践|Open Talk 杭州站沙龙在杭州西溪科创园顺利举办.本次活动邀请了有赞.个推.方得智能.又拍云等公司核心技术开发者,现场分享各自领域的大数据技术经验和 ...
- 分析 BAT 互联网巨头在大数据方向布局及大数据未来发展趋势
> 风起云涌的大数据战场上,早已迎百花齐放繁荣盛景,各大企业加速跑向"大数据时代".而我们作为大数据的践行者,在这个"多智时代"如何才能跟上大数据的潮流, ...
- 记一次由sql注入到拿下域控的渗透测试实战演练(下)
本次渗透使用工具: mimikatz,PsExec 本次渗透网络拓扑图: 开始渗透: 上一篇文章中我们讲到我们成功渗透了目标内网中web服务器并提取其管理员明文密码,通过明文密码又成功登陆了内网中的另 ...
- H - 看病要排队
看病要排队这个是地球人都知道的常识.不过经过细心的0068的观察,他发现了医院里排队还是有讲究的.0068所去的医院有三个医生(汗,这么少)同时看病.而看病的人病情有轻重,所以不能根据简单的先来先服务 ...