React - add condition with props.source (change class on specific component only)

0 votes
85 views
added May 3, 2021 in React by lcjr First Warrant Officer (9,190 points)
edited May 6, 2021 by lcjr
// navbar.tsx
import SocialShare from '../shared/SocialShare';
return (
  <SocialShare source="navbar" />
)

//SocialShare.tsx
type DropDownContainerProps = {
  source?: string;
};

const DropDownContainer = styled.div<DropDownContainerProps>`
  width: auto;
  margin: 0 auto;
  text-align: center;
  @media (min-width: 992px) {
    display: ${props => (props.source === 'navbar' ? 'none' : 'block')};
  }
`;

type SocialShareProps = {
  source?: string;
};

function SocialShare({ source }: SocialShareProps) {
  return(
   <>
     <DropDownContainer source="navbar">
   </>
  );
}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...