0

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.

4
  • Your question is a bit broad. Technically, yes, possible. Worth it? Probably not. Can you give us an example of what you expected that style.ts file would have? Commented Oct 12, 2022 at 8:23
  • What would make a lot more sense is to use a style.css file. Was that what you meant? Commented Oct 12, 2022 at 8:24
  • Well, @acdcjunior I don't have any idea how it would be implemented that's why I posted this question and never heard of such a scenario, so can't provide what it would have. Commented Oct 12, 2022 at 9:23
  • @super, I have used style.css a lot of times but I got the requirement to use style.ts as mentioned in the question, Commented Oct 12, 2022 at 9:25

1 Answer 1

1

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>;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.