export interface IconProps {
type: string;
className?: string;
title?: string;
onClick?: React.MouseEventHandler<any>;
spin?: boolean;
style?: React.CSSProperties;
}
const Icon = (props: IconProps) => {
const {type, className = "", spin} = props;
const classString = classNames({
anticon: true,
"anticon-spin": !!spin || type === "loading",
[`anticon-${type}`]: true,
}, className);
return <i {...omit(props, ["type", "spin"])} className={classString}/>;
};
export default Icon;
this is the simplest Icon component source code, see! spin here. I don"t understand why I use spin to write like this. At first, I thought that if spin is not passed in, then this value is undefined, so we need to use! undefined to convert to boolean type, but later I tested that undefined defaults to false, which does not seem to affect the result. I hope someone can solve the problem.
because it is written like this in many other components