0

I'm attemptiong to use a conditional inside of a "parent" conditional like so:

const linkStyle = {
    
    boxShadow: selectedTheme ? `${boxShadowConcatenated + {selectedTheme.button.buttonBoxShadow ? selectedTheme.button.buttonBoxShadow : "black" }}` : undefined,
    
  };

However, the selectedTheme.button. is underlined in red.

Any ideas how to make it work?

1
  • Updated my answer Commented Dec 9, 2020 at 3:10

2 Answers 2

1

How about using Optional Chaning?

for example, like below.

const linkStyle = {
  boxShadow: selectedTheme ? `${boxShadowConcatenated + selectedTheme.button?.buttonBoxShadow || "black"}` : undefined,
};
Sign up to request clarification or add additional context in comments.

1 Comment

@RogerStaxx selectedTheme.button?.buttonBoxShadow is actually do like selectedTheme.button && selectedTheme.button.buttonBoxShadow. but much shorter than.
0

const getLinkStyle = (selectedTheme) => {
  const boxShadowConcatenated = '5px 10px';
  
  return {
    boxShadow: selectedTheme && `${boxShadowConcatenated} ${selectedTheme.button?.buttonBoxShadow ||  "black"}`
  }
};
  
console.log(getLinkStyle({ button: { buttonBoxShadow: 'red' } }));
console.log(getLinkStyle({ button: {} }));
console.log(getLinkStyle());

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.