
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
react-native-use-modal
Advanced tools
Way to encapsulate your modal and get result by promise
showyarn add react-native-use-modal
# or
npm i react-native-use-modal
ModalProvider at your app's root component// App.tsx
import {ModalProvider} from 'react-native-use-modal';
const App = () => {
return <ModalProvider>
// ...
</ModalProvider>;
};
createUseModalcreateUseModal function receives a functional component of the specified type as the first argument.
This component will later be displayed as a modal.
// useSimpleModal.tsx
import {createUseModal} from 'react-native-use-modal';
// createUseModal creates a hook and returns it.
const useSimpleModal = createUseModal(
({
confirm, // Call this function to finish (confirm) modal
cancel, // Call this function to finish (cancel) modal
}) => {
// return react node to show as modal
return (
<View>
/* any view to presentation */
<Button onPress={confirm}>Ok</Button>
<Button onPress={cancel}>Cancel</Button>
</View>
);
},
);
..from any other react component
// FooView.tsx
const FooView = () => {
// Call the hook you declared earlier
// By calling the hook created with createUseModal, you can get an object that can display modal.
const simpleModal = useSimpleModal();
const handlePressButton = () => {
// Show modal!
// This returns a Promise<ModalResult>
simpleModal.show();
};
};
You can wait for modal to return the result with await
// FooView.tsx
const handlePressButton = async () => {
// Show modal!
// This returns a Promise<ModalResult>
const result = await simpleModal.show();
if (result.type === ModalResultType.CONFIRM) {
// handle confirm here
// ...
} else {
// handle cancel here
// ...
}
};
We sometimes need parameters to configure the modal.
// useAlertModal.tsx
import {createUseModal} from 'react-native-use-modal';
const useAlertModal = createUseModal<
void,
{title: string; message: string} // Declare parameters type
>(({confirm, cancel, param}) => {
return (
<View>
<Title>{param.title}</Title>
<Paragraph>{param.message}</Paragraph>
<View>
<Button onPress={confirm}>Ok</Button>
<Button onPress={cancel}>Cancel</Button>
</View>
</View>
);
});
// BarView.tsx
const BarView = () => {
// Call the hook you declared earlier
const alertModal = useAlertModal();
const handlePressButton = () => {
// Show modal!
// This returns a Promise<ModalResult>
alertModal.show({
title: 'Title',
message: 'Message',
});
};
};
Sometimes we may want to return a result from Modal.
export const useTextInputModal = createUseModal<string>(({confirm, cancel}) => {
const [value, setValue] = useState('');
const handlePressConfirm = () => confirm(value);
return (
<View style={styles.container}>
<TextInput
value={value}
onChangeText={setValue}
/>
<View >
<Button onPress={handlePressConfirm}>Confirm</Button>
<Button onPress={cancel}>Cancel</Button>
</View>
</View>
);
});
// BazView.tsx
const BazView = () => {
const textInputModal = useTextInputModal();
const handlePressButton = async () => {
// Show modal!
// This returns a Promise<ModalResult<string>>
const result = await textInputModal.show();
if (result.type === ModalResultType.CONFIRM) {
// handle confirm here
// You can find the entered value in result
console.log('entered: ' + result.data);
} else {
// handle cancel here
// ...
}
};
};
This package depends on react-native-modal and accept all its props.
You can set this in the second argument of the createUseModal.
For example, an animation could be set up like this:
export const useSimpleModal = createUseModal(
({confirm, cancel}) => {
/* render here */
},
{
modalProps: {
animationIn: 'fadeIn',
animationOut: 'fadeOut',
},
},
);
createUseModal supports all props, except for the isVisible property. We internally manage this property.
With these option, modal will cancel when press backdrop or back button. Each option can be set independently.
export const useSimpleModal = createUseModal(
({confirm, cancel}) => {
/* render here */
},
{
cancelOnBackButtonPress: true, // Default is false
cancelOnBackdropPress: true, // Default is false
},
);
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
FAQs
hooks for the react native modal
The npm package react-native-use-modal receives a total of 266 weekly downloads. As such, react-native-use-modal popularity was classified as not popular.
We found that react-native-use-modal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.