React Native library to detect clicks outside the component 👆
npm install react-native-click-outsideReact Native library to detect clicks outside the component 👆
!Build status - typescript compile
!License badge
!Latest, released version
!Date of latest commit
``sh`
yarn add react-native-click-outside
First of all, you need to wrap your app with ClickOutsideProvider as high as possible, for example in App.tsx:
`tsx
import { ClickOutsideProvider } from 'react-native-click-outside';
export const App = () => (
{ / rest of your app / }
);
`
Then you can call useClickOutside hook to detect clicks outside the component. First argument is the function that will be called every time user clicks outside of this component. It returns ref that you need to attach to the component you want to detect clicks outside of. For example:
`tsx
import { useClickOutside } from 'react-native-click-outside';
export default function MyComponent() {
const ref = useClickOutside
return (
);
}
``
See the contributing guide to learn how to contribute to the repository and the development workflow.