Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react笔记 #5

Open
duxinyues opened this issue Jul 27, 2020 · 0 comments
Open

react笔记 #5

duxinyues opened this issue Jul 27, 2020 · 0 comments

Comments

@duxinyues
Copy link
Owner

React在内存中创建一个虚拟的DOM,即为React-Dom,渲染器基于更改对浏览器DOM进行更新【只更新发生改变的部分】。

ReactElement

ReactDomElement,DOM元素的虚拟表示

ReactComponentElement,对应React组件的一个函数/类。

React.createElement(type,props,children):创建react元素

参数type,表示HTML元素标签,参数的形式是组件或者字符串;

参数props,表示定义元素属性,是一个属性对象;

参数children,子元素

createElement:简单表示就是创建什么、如何配置它、它包含什么。很多react组件就是react元素的集合。

高阶组件:不直接显示任何东西,而是修改或者增添其他组件的组件。

React类创建的组件拥有存储数据的支撑实例,只需返回单个react元素render。

state:程序在某个特定时间事物的信息。

state、props是React组件处理数据、通信的两种方式。

react通过this.state属性来访问可变状态,this.props属性来访问不可变状态;

state是react进行追踪的特殊属性,props是react传递不可变数据的主要方式。

React组件卸载是从DOM中移除组件的过程。

ComponentWillUnmount:监听组件卸载时的操作;

componentDidCatch(error,errorInfo):捕捉构造函数、渲染和生命周期方法中未捕获的错误;

当组件被移除之后,ComponentDidUnmount的生命周期就结束。

shouldComponentUpdate决定是否调用componentWillUpdate和componentDidUpdate。

ComponentWillMount挂载组件(即将挂载)

ComponentDidMount完成组件挂载【访问组件的状态属性、组件准备更新状态】。

react-redux

action、reducer、store。

store:状态来源

将action绑定到组件的action属性上

将组件链接到Redux store。将store作为属性传注入组件。

react-redux的connect工具函数,它会传入一个函数,mapSateToProps【接收一个状态作为参数,返回一个对象,与组件属性合并。第二参数mapDispatchToProps,将action绑定到组件上,该参数里面有一个dispatch函数,它就是注入到组件的dispatch方法。

reducer,是一个纯函数,负责计算store如何改变。在一个应用中出现多个reducer,分别负责store一个切片,使用Redux的combineReducer合并reducers成一个reducer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant