Created
September 14, 2023 08:02
-
-
Save hsoulier/d814bcf5cee42e2ad17cf3d0265e4fb3 to your computer and use it in GitHub Desktop.
Cheatsheet React composition TS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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