import React from "react" ; import usePlatform , { Platform , getPlatformsWithFallback , } from "./hooks/usePlatform" ; type Props = { supported ? : string [ ] ; notSupported ? : string [ ] ; platform ? : string ; noGuides ? : boolean ; children ? : React . ReactNode ; } ; const isSupported = ( platformKey , supported , notSupported ) : boolean | null => { if ( supported . length && supported . find ( p => p === platformKey ) ) { return true ; } else if ( notSupported . length && notSupported . find ( p => p === platformKey ) ) { return false ; } return null ; } ; export default ( { supported = [ ] , notSupported = [ ] , platform , noGuides , children , } ) : JSX . Element => { const [ currentPlatform ] = usePlatform ( platform ) ; if ( noGuides && ! ( currentPlatform as Platform ) . guides ) { return null ; } const platformsToSearch = getPlatformsWithFallback ( currentPlatform ) ; let result = null ; for ( let platformKey , i = 0 ; ( platformKey = platformsToSearch [ i ] ) ; i ++ ) { if ( ! platformKey ) continue ; result = isSupported ( platformKey , supported , notSupported ) ; if ( result === false ) return null ; else if ( result === true ) break ; } if ( result === null && supported . length ) return null ; return < React . Fragment > { children } < /React.Fragment>; } ;