Button onClick #1173
-
First of all! Congratulations on the amazing work! Remix really is very practical and simple! I would like to understand better about some stuff, but I can't find answers on documentation.
import { useNavigate } from "remix";
type ButtonProps = {
text: string;
onClick?: () => void;
fullWidth?: boolean;
contrast?: boolean;
to?: string;
};
export default function Button({ text, onClick, to, fullWidth = false, contrast = false}: ButtonProps) {
const navigate = useNavigate();
const width = fullWidth ? 'w-full' : 'w-48'
const bgColor = contrast ? 'bg-white hover:bg-blue-200' : 'bg-blue-700 hover:bg-blue-300';
const handleClick = () => (onClick && onClick()) || (to && navigate(to));
return (
<button onClick={handleClick} className={`${bgColor} rounded-lg p-2 ${width}`}>
{text}
</button>
);
} What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Every time some JS does not execute it's probably because you forgot to include |
Beta Was this translation helpful? Give feedback.
Every time some JS does not execute it's probably because you forgot to include
<Scripts />
inroot.tsx
, which can be done per-routehttps://remix.run/docs/en/v1/guides/disabling-javascript