Skip to content

jakex7/react-native-click-outside

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

react-native-click-outside

React Native library to detect clicks outside the component ๐Ÿ‘†

Build status - typescript compile License badge Latest, released version Date of latest commit

๐Ÿช„ 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

MIT

๐Ÿ“ Contribute

See the contributing guide to learn how to contribute to the repository and the development workflow.

Built with โ™ฅ๏ธ by Jakub Grzywacz

About

React Native library to detect clicks outside the component ๐Ÿ‘†

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •