I have created some stateless functional components that represent round social media icons used for links/sharing, the code looks like this:
AbstractRound
import React from 'react';
import { withStyles } from '@material-ui/core/styles';
const AbstractRound = ({
imgSrc,
classes,
alt,
}) => {
return (
<img
className={classes.root}
src={imgSrc}
alt={alt}
/>
);
};
const styles = {
root: {
//Some specific styling here relating to size, borderRadius, etc
},
};
export default withStyles(styles)(
AbstractRound
);
FacebookRound
import React from 'react';
import AbstractRound from './AbstractRound';
import img from './facebook.svg';
const FacebookRound = () => {
return (
<AbstractRound
imgSrc={img}
alt="Find us on Facebook"
/>
);
};
export default FacebookRound;
And then later, I'm going to use it like:
<FacebookRound/>
<GoogleRound/>
<TwitterRound/>
etc
Now it strikes me that I could do this a different way - something like:
import facebookImage from './facebook.svg';
import googleImage from './google.svg';
const SocialMediaRound = ({
classes,
variant,
}) => {
const variants = {
facebook: {
alt: "Find us on Facebook",
img: facebookImage
},
google: {
alt: "Find us on Google Plus",
img: googleImage
}
}
const {img, alt} = variants[variant]
return (
<img
className={classes.root}
src={img}
alt={alt}
/>
);
};
And use it like:
<SocialMediaRound variant = "facebook"/>
<SocialMediaRound varaint = "google"/>
The question is - is there any reason one is better than the other? In terms of bundling size - is the second way necessarily a larger bundle size than the first? (ie. what if I was creating a library of potentially 20 social media icons - but the user might only use three of them).
Certainly I think the first version is tidier.
What principles should I be paying attention to when making this kind of design decision?