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

Time:10-12

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.

CodePudding user response:

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>;
}
  • Related