react-native-click-outside
TypeScript icon, indicating that this package has built-in type declarations

0.1.1Β β€’Β PublicΒ β€’Β Published

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

/react-native-click-outside/

    Package Sidebar

    Install

    npm i react-native-click-outside

    Weekly Downloads

    10,206

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    39.5 kB

    Total Files

    45

    Last publish

    Collaborators

    • jake7