DEV Community

Agik Setiawan
Agik Setiawan

Posted on

3 2

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)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay