My question might be confusing but let me explain with an example here, let's say I have Button
component and it has 5 different props like (type, href, appearance...) and if we want to do following:
<Button type='button' href='<a { ...buttonProps }>Test Link</a>'/>
Basically attach all Button props to a
tag easily.
I found something similar over here but didn't get it. Any suggestions?
You need to change your button component and it should accept tag as property.
export default function Button({ Tag = "button", children, ...props }) {
return <Tag {...props}>{children}</Tag>;
}
use button like this.
<Button>Test</Button>
<Button Tag="a" href="https://stackoverflow.com/" target="_blank">
Test Link
</Button>
working codesandbox:
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments