如何在功能组件中使用compontdidmount?

2022-05-07

以下示例是关于Csharp中包含如何在功能组件中使用compontdidmount?用法的示例代码,想了解如何在功能组件中使用compontdidmount?的具体用法?如何在功能组件中使用compontdidmount?怎么用?如何在功能组件中使用compontdidmount?使用的例子?那么可以参考以下相关源代码片段来学习它的具体使用方法。

[英]:how to use componentdidmount in functional component源码类型:Csharp
// passing an empty array as second argument triggers the callback in useEffect
// only after the initial render thus replicating `componentDidMount` lifecycle behaviour
useEffect(() => {
  if(!props.fetched) {
 	 props.fetchRules();
  }
  console.log('mount it!');
}, []);

// componentDidUpdate
useEffect({
	your code here
}) 

// For componentDidUpdate
useEffect(() => {
  // Your code here
}, [yourDependency]);

// For componentWillUnmount
useEffect(() => {
  // componentWillUnmount
  return () => {
     // Your code here
  }
}, [yourDependency]);

本文地址:https://www.itbaoku.cn/snippets/785191.html