
react
欲语含羞
这个作者很懒,什么都没留下…
展开
-
PureComponent
原理 当组件更新时,如果组件的 props 和 state 都没发生改变, render 方法就不会触发,省去 Virtual DOM 的生成和比对过程,达到提升性能的目的。具体就是 React 自动帮我们做了一层浅比较: if (this._compositeType === CompositeTypes.PureClass) { shouldUpdate = !shallowEqual(p...原创 2020-04-26 00:31:39 · 144 阅读 · 0 评论 -
markdown目录锚点遍历实现
目录具体实现使用的antd 代码主要是把markdown文件中的标题取出来,按照层级关系遍历,转化成antd中Anchor的实现形式 比如,markdown文件中标题是一下形式 <a id="1" style="position: relative;top: -120px;">1</a> <a id="2" style="position: relative;top:...原创 2020-04-07 19:42:11 · 947 阅读 · 0 评论 -
react中的setState机制引发的坑
问题 今天在做作业的过程中,在class一个组件内,因为一个函数中的逻辑有些复杂,于是拆成若干个函数, 然后在一个函数中调用其他函数,但是运行的时候发现并不能运行出正常的结果。如以下函数, setEnterTime(time){ this.setState({ enterTime:time }); this.findMin() } 解决过程 使用浏览器对变量进行排查,发现enterTi...原创 2018-12-04 14:22:24 · 3756 阅读 · 3 评论 -
react中受控组件相关的warning
问题 今天在做作业的过程中,发现了一个报错信息,虽然不是error,但还是研究了一下 Warning: A component is changing an uncontrolled input of type text to be controlled.Input elements should not switch from uncontrolled to controlled (or vi...原创 2018-12-04 14:29:20 · 364 阅读 · 0 评论 -
react router中的withRouter
withRouter You can get access to the history object’s properties and the closest 's match via the withRouter higher-order component. withRouter will pass updated match, location, and history props to...原创 2019-01-15 17:13:44 · 5517 阅读 · 0 评论