Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
How to change variant of typography on condition when it's text are too long

I am new to using Material UI with ReactJs, TypeScript and trying to reduce the font size of typography when its text gets too large (3 or more lines) Here is my code snippet:-

     const x =() => {
    
    if(text.length > 12 )
        return "body1";
    else 
        return "subtitle2";
  };

  const renderTitle = () => {
    return (
      <Typography variant= {x} textAlign="center" lineHeight={1.2}>
        {text}
      </Typography>
    );
  };

But its given error like

Type '() => "subtitle2" | "body1"' is not assignable to type '"button" | "caption" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "inherit" | "subtitle1" | "subtitle2" | "body1" | "body2" | "overline" | undefined'.

is there any way to change variant="body1" when the text comes in 3rd line? Please help me

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try variant={x()}, because x in your case is a function.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!