摘要:数组件有函数作用域,每次render时,声明的方法会生成新的引用,声明的普通变量会重新声明并赋值初始值,而useRef和useState会保留状态。 1.useState 组件更新不会改变之前的状态,可以保存状态。值变化,会render,视图会更新,setState是异步的,同一个函数内设置的,不能
阅读全文
摘要:1.安装 React-Redux:首先,你需要将 React-Redux 安装到你的项目中。你可以使用 npm 或者 yarn 来安装它: npm install react-redux 2.创建 Redux Store:在你的应用程序中,创建 Redux store 来管理应用程序的状态。你可以使
阅读全文
摘要:某个组件更新,子组件也会一起更新 react更新采用时间切片,vue则是依赖收集 执行更新操作为16ms,如果操过16ms,先暂停更新,让浏览器先渲染 时间切片时间是16ms,因为人眼刷新率约60帧,60hz为16ms 1.避免state改为同样的值(class用PureComponent,函数组件
阅读全文
摘要:函数组件 1.函数组件没有生命周期 2.函数组件没有this 3.函数组件通过hook完成各种操作 4.函数组件本身就是render函数 5.props在函数第一个参数解释 useState 参考https://www.cnblogs.com/ssszjh/p/14581014.html props
阅读全文
摘要:ref获取dom context类似provider和injected,用于嵌套很深的爷孙组件传值 子组件使用父组件创建的context对象,不能自己创建 context创建在函数组件和class组件都是一样的 export let Context1 = React.createContext(''
阅读全文
摘要:1.class组件 初次挂载 1.constructor 2.getDerivedStateFromProps 3.render 4.componentDidMount 更新数据 1.getDerivedStateFromProps 2.shouldComponentUpdate 3.render
阅读全文
摘要:1.父子传值、插槽都是基于props 2.在react里父组件给组件传值跟具名插槽并无区别 3.子组件给父组件传值,也是利用props上定义方法,子组件拿到这个方法并传值 4.默认插槽,在子组件通过props.children获取 5.作用域插槽是通过父组件定义一个方法执行,子组件拿到这个方法并传值
阅读全文
摘要:1.class组件 class Cc extends React.Component { state = { show: true, arr: [{ name: '121' }, { name: "2323" }, { name: '432435' }] } handleShow() { this.
阅读全文
摘要:1.class组件 调用setState修改 1.setState是异步的,多次调用会合并为一次 2.修改同样数值的数据,仍会触发更新(解决方案:使用PureComponent) class Cc extends React.Component { state = { a: 1, c: [1, 2,
阅读全文
摘要:1.class组件 class组件中 事件绑定 会出现this丢失问题 1.给方法调用bind指向this 2.写成一个匿名箭头函数 3.方法本身写成箭头函数 4.若方法中带参数,只能用bind class Cc extends React.Component { f1(a?: any, b?: a
阅读全文
摘要:1.分为函数组件和class组件 函数组件 1.函数组件没有生命周期 2.函数组件没有this // 新写法 // 首字母大写才是组件 function Fc() { return <div> <Button type="primary">函数组件</Button> </div> } class组件
阅读全文