Last active
September 12, 2021 00:09
-
-
Save bootrino/702f4ec2e40564e1b06e403989376eb4 to your computer and use it in GitHub Desktop.
correct way to do typescript default props in react
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
type Props = { | |
onClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void; | |
color?: string; | |
hoverColor?: string; | |
width?: number; | |
height?: number; | |
} | |
export const IconRename: React.FC<Props> = ({ | |
onClick = () => {}, | |
color = "#c4c4c4", | |
hoverColor = "#00ff00", | |
width = 20, | |
height = 20, | |
...props | |
}) => { | |
const [getMouseOver, setMouseOver] = React.useState(false) | |
return ( | |
<div | |
onClick={onClick} | |
onMouseOver={() => setMouseOver(true)} | |
onMouseLeave={() => setMouseOver(false)} | |
> | |
<svg width={width} height={height} viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"> | |
<path | |
d="M491 1536l91-91-235-235-91 91v107h128v128h107zm523-928q0-22-22-22-10 0-17 7l-542 542q-7 7-7 17 0 22 22 22 10 0 17-7l542-542q7-7 7-17zm-54-192l416 416-832 832h-416v-416zm683 96q0 53-37 90l-166 166-416-416 166-165q36-38 90-38 53 0 91 38l235 234q37 39 37 91z" | |
fill={(getMouseOver) ? hoverColor : color} | |
/> | |
</svg> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment