Last active
June 30, 2025 12:02
-
-
Save audunolsen/99ebdbc5eac34bd9da090e69286b67dc to your computer and use it in GitHub Desktop.
Hmmmmmmm (PSEUDO CODE)
This file contains hidden or 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
function defineDefaultProps<Props>(defaultProps: NoInfer<Partial<Props>>) { | |
return function resolveDefaultProps(props: Props): Props { | |
return { | |
...defaultProps, | |
...props | |
} | |
} | |
} | |
interface Props { | |
theme?: 'light' | 'dark'; | |
children?: ReactNode; | |
} | |
const resolveDefaultProps = defineDefaultProps<Props>({ | |
theme: 'light' | |
}) | |
function Component(props: Props) { | |
const propsWithDefaults = resolveDefaultProps(props) | |
return ( | |
<div> | |
{propsWithDefaults.children} | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't like that you must break a very common eslint rule (no param reassign) if you want to keep the props name. Or you have to name the prop parameter something else lol