DEV Community

J E E N A R J U N
J E E N A R J U N

Posted on

2 1

How to adjust the size of the container based on the contents without repeating same lines of code?

I have few components rendered on based on certain conditions because of which the parent container sizing has to change.

export const Container = styled.div`
  display: grid;
  font-family: Nunito Sans;
  padding: 32px 40px 80px 80px;
  background-color: transparent;
  grid-template-columns: 980px;
  grid-template-rows: 40px minmax(64px, max-content);
  ${props =>
    props.extra &&
    css`
      grid-template-rows: 40px
…

Top comments (1)

Collapse
 
dance2die profile image
Sung M. Kim β€’

Seems it's already answered :)

You just need to define a boolean variable to have a flag if there are attachments or not and then use it to set the extra prop and to render or not the DetailsAttachments component like this:

renderData = () => {
  const attachments = [a, b, c, d, e];
…

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay