Skip to content

Instantly share code, notes, and snippets.

@hsoulier
Created September 14, 2023 08:02
Show Gist options
  • Save hsoulier/d814bcf5cee42e2ad17cf3d0265e4fb3 to your computer and use it in GitHub Desktop.
Save hsoulier/d814bcf5cee42e2ad17cf3d0265e4fb3 to your computer and use it in GitHub Desktop.
Cheatsheet React composition TS
import React from "react"
const Modal = ({ children }: { children: React.ReactNode }) => {
return React.Children.map(children, (child) => {
if (!React.isValidElement(child)) {
return null;
}
React.cloneElement(child);
});
};
const Cancel = ({ children }: { children: React.ReactNode }) => children;
const Close = ({ children }: { children: React.ReactNode }) => children;
Modal.Close = Close;
Modal.Cancel = Cancel;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment