Basic example:
import React from "react";
import usePortal from "./Hooks/usePortal";
function App() {
const { Portal } = usePortal({});
return (
<div className="App">
<Portal>Hello Portal!!</Portal>
</div>
);
}
export default App;
Advanced example:
import React from "react";
import usePortal from "./Hooks/usePortal";
function App() {
const { Portal, isShow, show, hide, toggle } = usePortal({
defaultShow: false,
onShow: () => {
console.log("Show");
},
onHide: () => {
console.log("Hide");
},
});
return (
<div className="App">
<button onClick={show}>Show</button>
<button onClick={hide}>Hide</button>
<button onClick={toggle}>Toogle</button>
<p>Status => {isShow.toString()}</p>
<hr />
<Portal>Hello World!!</Portal>
</div>
);
}
export default App;
containerId
- Container Id (default "use-portal-react")defaultShow
- Show/hide component at startup (default true)onShow
- Function that runs when the component is renderedonHide
- Function that runs when the component is unmounted
Portal
- React ComponentisShow
- Component statusshow
- Function Showing Componenthide
- Function that hides the Componenttoggle
- Function Showing/hides Component
--- Coming soon ---
Basic example:
import React from "react";
import useModal from "./Hooks/useModal";
function App() {
const { Modal } = useModal({});
return (
<div className="App">
<Modal>Hello Modal!!</Modal>
</div>
);
}
export default App;
Advanced example:
import React from "react";
import useModal from "./Hooks/useModal";
function App() {
const { Modal, isShow, show, hide, toggle } = useModal({
showClose: false,
clickOutsideToHide: true,
onShow: () => {
console.log("Show");
},
onHide: () => {
console.log("Hide");
},
});
return (
<div className="App">
<button onClick={show}>Show</button>
<button onClick={hide}>Hide</button>
<button onClick={toggle}>Toogle</button>
<p>Status => {isShow.toString()}</p>
<hr />
<Modal>Hello World!!</Modal>
</div>
);
}
export default App;
containerId
- Container Id (default "use-portal-react")defaultShow
- Show/hide component at startup (default true)onShow
- Function that runs when the component is renderedonHide
- Function that runs when the component is unmountedclickOutsideToHide
- Unmounted componente click out side to hide (default false)showClose
- Show/hide close buttonescToHide
- "Esc" key to unmount component
Modal
- React ComponentisShow
- Component statusshow
- Function Showing Componenthide
- Function that hides the Componenttoggle
- Function Showing/hides Component
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
This project was bootstrapped with Create React App.
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
This project was bootstrapped with Create React App.