ducky_L

导航

2023年4月21日 #

react 组件间通信

摘要: 1、父子组件通信:props+回调函数 2、爷孙组件通信:两层父子通信或者使用 Context.Provider 和 Context.Consumer 3、任意组件通信--》状态管理:redux、Mobx,zustand等状态管理库 阅读全文

posted @ 2023-04-21 16:58 ducky_L 阅读(12) 评论(0) 推荐(0) 编辑

react 生命周期钩子函数

摘要: 1、挂载:construct、getDerivedStateFromProps、render、componentDidMounted 2、更新:getDerivedStateFromProps、componentWillUpdate、render、getSnapshotBeforeUpdate、co 阅读全文

posted @ 2023-04-21 15:14 ducky_L 阅读(12) 评论(0) 推荐(0) 编辑

react ref

摘要: 一、使用 ref 操作 DOM 1、要访问由 React 管理的 DOM 节点,首先,引入 useRef Hook: import { useRef } from 'react'; 2、然后,在你的组件中使用它声明一个 ref: const myRef = useRef(null); 3、最后,将其 阅读全文

posted @ 2023-04-21 15:03 ducky_L 阅读(13) 评论(0) 推荐(0) 编辑