react-native-click-outside
v0.1.1
Published
React Native library to detect clicks outside the component ๐
Downloads
20,544
Readme
react-native-click-outside
React Native library to detect clicks outside the component ๐
๐ช Installation
yarn add react-native-click-outside
๐ Usage
First of all, you need to wrap your app with ClickOutsideProvider
as high as possible, for example in App.tsx
:
import { ClickOutsideProvider } from 'react-native-click-outside';
export const App = () => (
<ClickOutsideProvider>
{ /* rest of your app */ }
</ClickOutsideProvider>
);
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:
import { useClickOutside } from 'react-native-click-outside';
export default function MyComponent() {
const ref = useClickOutside<View>(() => console.log('clicked outside A'));
return (
<View ref={ref}>
<Text>Test</Text>
</View>
);
}
โ๏ธ License
๐ Contribute
See the contributing guide to learn how to contribute to the repository and the development workflow.