Last active
June 7, 2022 21:45
-
-
Save Keraito/efd3b734cb502f285777a299bda37696 to your computer and use it in GitHub Desktop.
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
type OtherComponentProps = { | |
// ... | |
onChange?: (value: number) => void; | |
}; | |
// ----- | |
const Component = () => { | |
// We know for sure it's not nullable as we're initialising it, but TypeScript doesn't so we have to help it. | |
const changeValue = useCallback<NonNullable<OtherComponentProps["onChange"]>>( | |
(value) => { | |
if (value > 0) { | |
doSomethingWithTheValue(value); | |
} | |
}, | |
[] | |
); | |
return <SomeOtherComponent onChange={changeValue} />; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment