Hi all trying to make a button component that converts to an anchor tag when changing a prop. Im using a switch statement but nothing changes when I change the prop and the onClick is not being handled? Im using NextJS's Link component for the anchor tag
const Button = ({ children }, props) => {
switch (props.as) {
case 'link':
return (
<Link
href={props.link}
onClick={props.click}
className={styles.hello}>
{props.icon && <FontAwesomeIcon icon={props.icon} />}
{children}
</Link>
);
case 'button':
return (
<button
onClick={props.click}
type='button'
className={styles.btn}>
{props.icon && <FontAwesomeIcon icon={props.icon} />}
{children}
</button>
);
default:
return (
<button
onClick={props.click}
type='button'
className={styles.btn}>
{props.icon && <FontAwesomeIcon icon={props.icon} />}
{children}
</button>
);
}
};
in my Parent component I'm importing the Button and using it like:
<Button
as='link'
icon='coffee'
click={props.handleAccept}>
RSVP
</Button>
In render it appears a button rather than expected anchor tag. Any ideas please?
console.log(props.as)inside theButtoncomponent to verify that the prop's value is what you expect?