Skip to content

SergoMorello/react.native.hoc.modal

Repository files navigation

React.hoc.modal

React component for easy create modals

install

npm i react-native-hoc-modal

Examples

Create modal component

// MyFirstModal.jsx
...
import Modal from 'react-hoc-modal';

const MyFirstModal = () => {

	return(<View>
		<Text>Hello, i am you first modal component</Text>
	</View>);
};

export default Modal.withModal(MyFirstModal);

Mount modal component

// App.jsx
...
import MyFirstModal from "./MyFirstModal";
...
const App = () => {
	...
	return(
		...
		<MyFirstModal/>
	);
}

Use modal component

<Button onPress={MyFirstModal.show} title="Show my first modal"/>

If you need update data without 'props', you can use the 'setState' method.

MyFirstModal.setState({testData: 'Hello'});

To get data use the 'state' property in the returned 'useModal' hook object.

const MyFirstModal = () => {
	const {state} = Modal.useModal();

	return(<View>
		<Text>{state?.testData}</Text>
	</View>);
};

About

React Native Hoc Modal

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published