useMount
//utils/index.js
export const useMount = (callback) => {
useEffect(() => {
callback()
}, [])
}
使用
import {
useMount } from 'utils';
useMount(() => {
console.log('组件挂载时执行一次 ');
// fetch(`${apiUrl}/users`).then(async response => {
// console.log('response2', response);
// if (response.ok) {
// setUsers(await response.json());
// }
// });
});