首页 > 其他分享 >react typescript封装函数式组件styled-component

react typescript封装函数式组件styled-component

时间:2023-02-14 10:37:57浏览次数:35  
标签:loading const boolean component react typescript IButton styled children


interface IButton {
margin?: boolean;
width?: string;
justify?: JustifyContentProps;
}

const Button = styled.button<IButton>`
.....
`;


interface ILoadButton extends IButton, DOMAttributes<HTMLButtonElement> {
loading?: boolean;
}

export const LoadButton: FC<ILoadButton> = ({
loading,
children,
...props
}) => (
<Button {...props}>
{loading ? <LoadIcon /> : null}
{children}
</Button>
);


标签:loading,const,boolean,component,react,typescript,IButton,styled,children
From: https://blog.51cto.com/u_15964288/6055860

相关文章

  • 在next.js中使用styled-component以及全局主题切换
    文章目录​​使styled-component像SPA中使用​​​​step1安装插件​​​​step2根目录下创建`.babelrc`​​​​step3创建`page/_document.js`自定义Document​​​......
  • styled-components给svg添加动画
    ​​https://stackoverflow.com/questions/68043891/inherited-svg-functional-component-cannot-add-style-styled-components​​如下直接继承react组件然后添加样式居......
  • 前端二面经典react面试题
    如何解决props层级过深的问题使用ContextAPI:提供一种组件之间的状态共享,而不必通过显式组件树逐层传递props;使用Redux等状态库。react实现一个全局的dialogimpo......
  • 问:你是如何进行react状态管理方案选择的?
    前言:最近接触到一种新的(对我个人而言)状态管理方式,它没有采用现有的开源库,如redux、mobx等,也没有使用传统的useContext,而是用useState+useEffect写了一个发布订阅者模式进......
  • 京东前端react面试题及答案
    useEffect与useLayoutEffect的区别(1)共同点运用效果:useEffect与useLayoutEffect两者都是用于处理副作用,这些副作用包括改变DOM、设置订阅、操作定时器等。在函数......
  • 问:React的useState和setState到底是同步还是异步呢?
    先来思考一个老生常谈的问题,setState是同步还是异步?再深入思考一下,useState是同步还是异步呢?我们来写几个demo试验一下。先看useState同步和异步情况下,连续执行两......
  • React.cloneElement
    React.cloneElement()接收三个参数第一个参数接收一个ReactElement,可以是真实的dom结构也可以是自定义的。第二个参数返回旧元素的props、key、ref。可以添加新的props,第......
  • styled-components ts频繁检查出错 keyframes
    正常的书写到了ts后频繁出错代码规范上了ts检查后如图让人烦躁的检查查出一堆不知所以的问题换一种写法通过了检测单显然这不是一个好方法ts-styled-plugin有待加......
  • ReactNative Tried to register two views with the same name RNCViewPager
    因为有两个包用到了一个库,但是使用的版本不同改过来就好了......
  • aws-amplify-react-native null is not an object (evaluating ‘RNAWSCognito.compou
    使用aws-amplify-react-native原来是托管expo项目,eject后登录时报了这个问题解决安装​​​amazon-cognito-identity-js​​react-nativelinkamazon-cognito-identity-......