handleClick for BlackButton
This commit is contained in:
parent
f855b88110
commit
77effde428
1 changed files with 13 additions and 4 deletions
|
@ -1,12 +1,21 @@
|
|||
import '../../css/customButton.css'
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
function BlackButton({ text , to="/"}) {
|
||||
function BlackButton({ text , to="/", onClick }) {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleClick = (e) => {
|
||||
if (onClick) {
|
||||
onClick(e);
|
||||
}
|
||||
if (!e.defaultPrevented && to) {
|
||||
navigate(to, { replace: true });
|
||||
}
|
||||
};
|
||||
|
||||
return(
|
||||
<button className='gray' onClick={()=> navigate(to, { replace: true })}>{text}</button>
|
||||
<button className='gray' onClick={handleClick}>{text}</button>
|
||||
)
|
||||
}
|
||||
|
||||
export default BlackButton
|
||||
|
||||
export default BlackButton
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue