How to check if callback exists in props in react native?

Viewed 26

I have this component that has these props:

export type Props = NavigationScreenProps & {

    name: string
    testCallback?: () => void

}

How do I check if this callback exists and then call the callback?

1 Answers

You can simply do

const {testCallback = null} = props || {}

if(testCallback){
testCallback()
}
Related