Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

React 16+ 里如何使用生命周期

我自己用的是蚂蚁的 Antd 但里面用的是:

const Login: React.FC<{}> = () => {
    ....
    return (
     <div className={styles.container}>
    )
}

请问这里怎么去使用生命周期呢?例如我想页面加载后去请求或者弹窗之类的?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

React 的组件分函数组件和类组件。React.FC 是函数组件的写法,而生命周期函数是类组件的。
如果想在函数组件里去做一些类似的操作的话,可以用 hooks。
比如页面加载后去xxx的话就是 useEffect

useEffect(() => {
  // 请求或者弹窗的处理
}, []);

https://zh-hans.reactjs.org/d...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...