随笔分类 -  react

摘要:1,关于公共组件逻辑的抽离 mixin。已被弃用 高阶组件 HOC:不是一个功能,而是一种模式。封装了公共逻辑,抛出原组件。 Render Props:将class组件中的state,作为props,传递给函数组件。 与HOC的区别,用函数包裹,返回一个新组件。 阅读全文
posted @ 2020-12-18 15:56 毛栗的demo 阅读(167) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2020-12-07 17:50 毛栗的demo 阅读(108) 评论(0) 推荐(0)
摘要:1,useEffect 会在每次渲染后(包括挂载,更新)都执行,DOM更新完毕。 2,useEffect区别: 3,useEffect如何在 componentWillUnmount 清除计时器,监听事件等。 阅读全文
posted @ 2020-12-07 17:47 毛栗的demo 阅读(82) 评论(0) 推荐(0)
摘要:1,hook 采用了js的闭包特性,可以在函数内 调用state。 2,useState 运用的是数组结构的方式定义变量。 阅读全文
posted @ 2020-12-07 17:38 毛栗的demo 阅读(72) 评论(0) 推荐(0)
摘要:1, React 默认:父组件有更新,子组件则无条件也更新!!! 2, 性能优化对于 React 更加重要! 3, shouldComponentUpdate 一定要每次都用吗?—— 需要的时候才优化 4,shouldComponentUpdate 一定要配合不可变值一起使用。如果没有使用不可变值, 阅读全文
posted @ 2020-12-07 16:14 毛栗的demo 阅读(129) 评论(0) 推荐(0)
摘要:1,import 2,react.lazy() 3, react.suspence() 阅读全文
posted @ 2020-12-04 16:22 毛栗的demo 阅读(128) 评论(0) 推荐(0)
摘要:1,公共信息的传递(主题,语言) 2,用props太繁琐 3,用redux太小题大作。 import React from 'react' // 创建 Context 填入默认值(任何一个 js 变量) const ThemeContext = React.createContext('light' 阅读全文
posted @ 2020-12-04 16:09 毛栗的demo 阅读(123) 评论(0) 推荐(0)
摘要:传送门功能:将组件提到指定位置,不影响组件编写结构。 1,overflow:hidden; 2,z-index 3,position:fixed(body 根处) 阅读全文
posted @ 2020-12-04 15:42 毛栗的demo 阅读(82) 评论(0) 推荐(0)
摘要:1,input的值不受state改变。通过ref获取。 2,ref,defaultValue,defaultChecked 3,场景:必须操作DOM,setState实现不了。eg:<input type='file'>、富文本编辑 4,与受控组件比较,受控组件更符合react设计思想。 阅读全文
posted @ 2020-12-04 15:35 毛栗的demo 阅读(102) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2020-12-03 16:58 毛栗的demo 阅读(66) 评论(0) 推荐(0)
摘要:一,不可变值: 1,不能在setState外面,改变state本身的值。 二,同步或者异步 1,直接使用是异步的。setState可以传回调函数。 2,在setTimeout中使用是同步的。 3,在自定义DOM事件中,是同步的。 三,可能会被合并 阅读全文
posted @ 2020-12-03 16:28 毛栗的demo 阅读(66) 评论(0) 推荐(0)
摘要:props:传递数据、传递函数、类型检查。 阅读全文
posted @ 2020-12-03 15:38 毛栗的demo 阅读(94) 评论(0) 推荐(0)
摘要:与原生event的差异: form: 受控组件:通过自定义onChange事件,来控制input的value值,受state控制。 非受控组件:表单值不受state控制。 阅读全文
posted @ 2020-12-03 15:25 毛栗的demo 阅读(91) 评论(0) 推荐(0)