Skip to content

Instantly share code, notes, and snippets.

@brandonchadlange
Created September 26, 2022 20:07
Show Gist options
  • Save brandonchadlange/8e56672958020891fe10ac4cae7b1cd4 to your computer and use it in GitHub Desktop.
Save brandonchadlange/8e56672958020891fe10ac4cae7b1cd4 to your computer and use it in GitHub Desktop.
Loosely coupled modal implementation
import useModal from "@/components/modal";
const App = () => {
const AppModal = useModal({
Body: (props) => (
<>
<h1>Hello from my modal!</h1>
<button onClick={props.close}>Close</button>
</>
),
});
return(
<>
<button onClick={AppModal.open}>Open Modal</button>
<AppModal.Modal />
</>);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment