Created
July 15, 2017 13:29
-
-
Save tai2/04895e2dc35edbfa024c98e264b5c4d4 to your computer and use it in GitHub Desktop.
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
// Aはpropsで装飾用のコンポーネントを受け取りたい | |
// ただし、装飾用のコンポーネントが必要とするpropsについては関知したくない | |
function A(props) { | |
const Decorator = props.decorator; | |
return ( | |
<div> | |
<Decorator {...props.decoratorProps}>TEST</Decorator> | |
</div> | |
); | |
} | |
// styleを受け取っているのは、ただの例で、これといった意味はない | |
function HeadingDecorator(props) { | |
return <h1 style={props.style}>{props.children}</h1>; | |
} | |
function f(props) { | |
return <A decorator={HeadingDecorator} decoratorProps={{style: props.style}/>}} />; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment