1

Hi all I have following code: my code

As you see I have "mystyle" which have fontSize: 35px and color:"red".

      const mystyle = {
        fontSize: "35px",
        color: "red"
      };

Also I added react-responsive helper to set World component visible when max-width will equal to 600px.

    const isMobile = useMediaQuery({ query: "(max-width: 600px)" });
    return (
      <div>
        <div style={mystyle}> hello </div>
        {isMobile && <World />}
      </div>
   );

Now my question is: How can I change fontSize to 20px and color to "blue" in my "mystyle" when max-width will equal to 600px ?

1 Answer 1

2
const mystyle = {
        fontSize: "35px",
        color: "red"
};

const mystyle2 = {
        fontSize: "20px",
        color: "blue"
};

<div style={isMobile ? mystyle2 : mystyle}> hello </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.