Ali Nawaz
Ali Nawaz

Reputation: 65

is it possible to style typescript react app with style.ts file?

I am new to typescript and I got a requirement that I have to style my app with a style.ts file but don't know how or either is it possible. Need a detailed answer if it is possible and how to use it and what are the advantages of this technique.

Upvotes: 0

Views: 1424

Answers (1)

Anis
Anis

Reputation: 1220

Yes it is possible to do it in within typescript file, you can do as

in style.ts file

export const divStyle: {color: string, backgroundImage: string} = {
  color: 'blue',
  backgroundImage: 'url(' + imgUrl + ')',
};

and then you can use it in your component as

import {divStyle} from './style'
function HelloWorldComponent() {
  return <div style={divStyle}>Hello World!</div>;
}

Upvotes: 1

Related Questions