DEV Community

Agik Setiawan
Agik Setiawan

Posted on

How to create Style with typed safe in React JS

That ways very simple using 'CSSProperties'

import { CSSProperties } from "react";
Enter fullscreen mode Exit fullscreen mode

create style

const BannerStyle : CSSProperties = {
        background: `url(/img/product/shop-bg.jpg)`,
        backgroundRepeat:'no-repeat',
        backgroundPosition:'center center',
        backgroundSize:'cover',
        position:'relative'
    }
Enter fullscreen mode Exit fullscreen mode

and then use style into html tag

<div style={BannerStyle}>
</div>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)