Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tai2
Created July 15, 2017 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tai2/04895e2dc35edbfa024c98e264b5c4d4 to your computer and use it in GitHub Desktop.
Save tai2/04895e2dc35edbfa024c98e264b5c4d4 to your computer and use it in GitHub Desktop.
// 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