REACT 学习
react
react 组件实例的三大属性 state props refs
方法用箭头函数改this 的指向
class
类中所有定义的方法在局部都开启了严格模式 use strict
class Person{ a = "测试" constructor(){ } say(){ console.log(this) } } const p1 = new Person() const x = p1.say x() // undefined
类里面能写那些代码
构造器 自定义方法 赋值语句
react 生命周期
挂载
构造器 constructor() 组件将要挂载 componentWillMount() 挂载 render() 组件挂载完毕 componentDidMount() 组件将要卸载 componentWillUnmount()
setState()
更新
控制组件更新 shouldComponentUpdate(){return true} 组件将要更新 componentWillUpdate() 更新 render() 组件更新完毕 componentDidUpdate()
强制更新
forceUpdate()
组件将要更新 componentWillUpdate() 更新 render() 组件更新完毕 componentDidUpdate()
父组件更新
子组件 将要接收到props
componentWillReceiveProps() (第一次不调用)
组件卸载操作 ReactDom.unmountComponentAtNode()
react 新生命周期 三个will钩子前加 UNSAFE (除了componentWillUnmount)
getDerivedStateFromProps(props,state){return props} 从props 派生到state
getSnapshotBeforeUpdate(){ return snapshotValue }
组件更新完毕的钩子
componentDidUpdate(prevprops,prevstate,snapshotValue){}
react-router-dom 路由 switch 使用
<Switch> 是唯一的因为它仅仅只会渲染一个路径。相比之下(不使用<Switch>包裹的情况下),每一个被location匹配到的<Route>将都会被渲染
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!