This file contains hidden or 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 { Subtract, Omit } from 'utility-types'; | |
| import MakeCounter, { MakeCounterProps, InjectedCounterProps } from './MakeCounter'; | |
| type MakeCounterHocProps = Omit<MakeCounterProps, 'children'>; | |
| const makeCounter = <P extends InjectedCounterProps>( | |
| Component: React.ComponentType<P> | |
| ): React.SFC<Subtract<P, InjectedCounterProps> & MakeCounterHocProps> => ({ | |
| minValue, | |
| maxValue, |
This file contains hidden or 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
| interface CounterProps extends InjectedCounterProps { | |
| style: React.CSSProperties; | |
| } | |
| const Counter = (props: CounterProps) => ( | |
| <div style={props.style}> | |
| <button onClick={props.onDecrement}> - </button> | |
| {props.value} | |
| <button onClick={props.onIncrement}> + </button> | |
| </div> |
This file contains hidden or 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
| interface CounterProps { | |
| style: React.CSSProperties; | |
| value: number; | |
| minCounterValue?: number; | |
| maxCounterValue?: number; | |
| } | |
| const Counter = (props: CounterProps) => ( | |
| <MakeCounter | |
| minValue={props.minCounterValue} |
This file contains hidden or 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
| interface CounterProps { | |
| style: React.CSSProperties; | |
| minValue?: number; | |
| maxValue?: number; | |
| } | |
| const Counter = (props: CounterProps) => ( | |
| <MakeCounter minValue={props.minValue} maxValue={props.maxValue}> | |
| {injectedProps => ( | |
| <div style={props.style}> |
This file contains hidden or 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
| interface InjectedCounterProps { | |
| value: number; | |
| onIncrement(): void; | |
| onDecrement(): void; | |
| } | |
| interface MakeCounterProps { | |
| minValue?: number; | |
| maxValue?: number; | |
| children(props: InjectedCounterProps): JSX.Element; |
This file contains hidden or 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
| const withLoading = Component => ({ loading, ...props }) => | |
| loading ? <LoadingSpinner /> : <Component {...props} />; |
This file contains hidden or 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
| export interface InjectedCounterProps { | |
| value: number; | |
| onIncrement(): void; | |
| onDecrement(): void; | |
| } | |
| interface MakeCounterProps { | |
| minValue?: number; | |
| maxValue?: number; | |
| } |
This file contains hidden or 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 makeCounter, { InjectedCounterProps } from './makeCounter'; | |
| interface CounterProps extends InjectedCounterProps { | |
| style?: React.CSSProperties; | |
| } | |
| const Counter = (props: CounterProps) => ( | |
| <div style={props.style}> | |
| <button onClick={props.onDecrement}> - </button> | |
| {props.value} |
This file contains hidden or 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 { Subtract } from 'utility-types'; | |
| export interface InjectedCounterProps { | |
| value: number; | |
| onIncrement(): void; | |
| onDecrement(): void; | |
| } | |
| interface MakeCounterState { | |
| value: number; |
This file contains hidden or 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
| const withLoading = <P extends object>( | |
| Component: React.ComponentType<P> | |
| ): React.FC<P & WithLoadingProps> => ({ | |
| loading, | |
| ...props | |
| }: WithLoadingProps) => | |
| loading ? <LoadingSpinner /> : <Component {...props as P} />; |