Skip to content

Instantly share code, notes, and snippets.

@audunolsen
Last active June 30, 2025 12:02
Show Gist options
  • Save audunolsen/99ebdbc5eac34bd9da090e69286b67dc to your computer and use it in GitHub Desktop.
Save audunolsen/99ebdbc5eac34bd9da090e69286b67dc to your computer and use it in GitHub Desktop.
Hmmmmmmm (PSEUDO CODE)
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>
)
}
@audunolsen
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment