Answer the question
In order to leave comments, you need to log in
How to create a generic button?
How to create a universal button component, if visually it is more or less similar to other buttons, but when clicked, it does different functionality?
How to do this if you can not put an event handler on the component?
I see the only way out
<Button color={"inherit"}/>
<div onClick={() => {
toggleAdd(!open)
setUser("")
setPhone("")
}}>
<Button color={"inherit"}/>
</div>
export const Button = ({phone, text, color, textColor, border}) => {
return (
<>
{phone ? (
<a className="phone" href={`tel:${phone}`} ><img src="./Assets/Phone.svg" alt="" /></a>
):(
<button
className="submit"
style={{
background: color,
color: textColor,
border: border,
}}
>
{text}
</button>
)}
</>
)
}
Answer the question
In order to leave comments, you need to log in
How to create a universal button component, if visually it is more or less similar to other buttons, but when clicked, it does different functionality?
How to do this if you can not put an event handler on the component?
clsx
and pass styles through className inside the component through props<Button className="button-any">Какой-то текст</Button>
How to do this if you can not put an event handler on the component?
I don't understand why you need to swap the link with the button, what's the point?
I understand you want to make the button one but for different purposes, but it’s not very good to do it in my opinion
//css
.submit.myStyles1 {
}
.submit.myStyles2 {
}
.submit.myStyles3 {
}
const myfunction1 = () => {}
const myfunction2 = () => {}
const PhoneBTN = ({phone}) => (
<a className="phone" href={`tel:${phone}`}>
<img src="./Assets/Phone.svg" alt="" />
</a>
)
const Button = ({type,text}) => {
return (
type === "phone" ?
<PhoneBTN {...{phone:text}} onClick={myfunction1}/>:
<button className="submit myStyles" onClick={myfunction2}>{text}</button>
)
}
const render = () => (
<Button {...{type:"phone",text:""}}/>
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question