Download wp-calypso/packages/components/src/component-swapper/index.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 813 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/components/src/component-swapper/index.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/components/src/component-swapper/index.tsx
-
curl -L -o index.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/components/src/component-swapper/index.tsx
813 Bytes
| import { useBreakpoint } from '@automattic/viewport-react'; | |
| import React, { ReactNode, useEffect } from 'react'; | |
| const ComponentSwapper = ( { | |
| className, | |
| breakpoint = '<660px', // breakpoints from mediaQueryLists from '@automattic/viewport' | |
| breakpointActiveComponent, | |
| breakpointInactiveComponent, | |
| onSwap, | |
| children, | |
| }: { | |
| children?: ReactNode; | |
| breakpoint: string; | |
| breakpointActiveComponent: React.ReactElement; | |
| breakpointInactiveComponent: React.ReactElement; | |
| onSwap?: () => void; | |
| className?: string; | |
| } ) => { | |
| const isActive = useBreakpoint( breakpoint ); | |
| useEffect( () => { | |
| onSwap?.(); | |
| }, [ isActive, onSwap ] ); | |
| return ( | |
| <div className={ className }> | |
| { isActive ? breakpointActiveComponent : breakpointInactiveComponent } | |
| { children } | |
| </div> | |
| ); | |
| }; | |
| export default ComponentSwapper; | |