其他分享
首页 > 其他分享> > Delay组件

Delay组件

作者:互联网

import { useState, useEffect } from 'react';
import PropTypes from 'prop-types';

const Delayed = ({ children, delay }) => {
const [isShow, setIsShow] = useState(false);

useEffect(() => {
 setTimeout(() => {
  setIsShow(true);
 }, delay);
}, [delay]);

return isShow ? children : null;
};

Delayed.propTypes = {
children: PropTypes.node,
delay: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};

export default Delayed;

 

标签:delay,Delayed,Delay,PropTypes,useState,组件,useEffect,children
来源: https://www.cnblogs.com/it-Ren/p/16352885.html