小编Sha*_*Ali的帖子

如何在react中使用typescript在div中传递样式

这是我的代码,我只想制作一个与打字稿反应的自定义组件,就像我想传递高度、宽度、边框半径和样式作为额外参数一样,如果我想要更多 css 属性,那么传递 style={{display:flex}但我无法用打字稿添加它,我成功地用 js 编写了它,但不熟悉打字稿

我的界面

interface BoxProps {
    heights: React.CSSProperties;
    styles?: React.CSSProperties;
    className?: String;
    borderRadius?: React.CSSProperties
    children?: React.ReactElement<any>
}

const Box = ({ id, heights, styles, className, children }: BoxProps) => {
    const Nstyle = { ...styles,height: { heights } }
    return (
        <div
            {...id}
            style={Nstyle}
            className={CN} >
            {children}
        </div >
    );
}
Run Code Online (Sandbox Code Playgroud)

请帮助样式通过打字稿 The expected type comes from property 'style' which is declared here on type“DetailedHTMLProps, HTMLDivElement>”显示此错误

typescript reactjs

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

reactjs ×1

typescript ×1