Skip to content

Instantly share code, notes, and snippets.

@speckworks
Created March 27, 2020 16:50
Show Gist options
  • Save speckworks/81d09ef0feb4a16a367dc0f33fcf3a4d to your computer and use it in GitHub Desktop.
Save speckworks/81d09ef0feb4a16a367dc0f33fcf3a4d to your computer and use it in GitHub Desktop.
Specialization of Components in ReactJS.
<div id="root">
<!-- This div's content will be managed by React. -->
</div>
function FancyBorder(props) {
return (
<div className={'FancyBorder FancyBorder-' + props.color}>
{props.children}
</div>
);
}
function Dialog(props) {
return (
<FancyBorder color="blue">
<h1 className="Dialog-title">
{props.title}
</h1>
<p className="Dialog-message">
{props.message}
</p>
</FancyBorder>
);
}
function HowdyDialog() {
return (
<Dialog
title="Howdy!"
message="Thank you for tasting specialized components with me!" />
);
}
ReactDOM.render(
<HowdyDialog />,
document.getElementById('root')
);
<script src="https://unpkg.com/react/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script>
.FancyBorder {
padding: 10px 10px;
border: 10px solid;
border-radius:10%;
}
.FancyBorder-blue {
border-color: purple;
}
.Dialog-title {
margin: 10;
font-family: sans-serif;
}
.Dialog-message {
margin: 10px;
font-size: larger;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment