<div id="app"></div>
body {
background: #202020;
box-sizing: border-box;
font-family: Menlo, Monaco, sans-serif;
}
h4, p {
font-family: Menlo, Monaco, sans-serif;
}
#app {
padding: 15px;
display: flex;
}
.app {
margin: auto;
display: flex;
flex-wrap: wrap;
flex: 1 1 100%;
}
.blue-wrapper {
display: flex;
flex-wrap: wrap;
flex: 1 1 30%;
margin: auto;
font-family: Menlo, Monaco;
background: #066ace;
color: white;
border-radius: 5px;
max-width: 700px;
padding: 15px;
margin-bottom: 15px;
input {
flex: 1 0 100%;
margin-bottom: 10px;
border-radius: 3px;
border: none;
font-size: 30px;
font-weight: bold;
}
.update {
flex: 1 0 100%;
text-align: center;
margin: 20px auto;
color: yellow;
}
.black-tile {
display: flex;
box-sizing: border-box;
flex-wrap: wrap;
flex: 0 0 45%;
text-align: center;
margin: 10px auto;
border: 1px solid white;
background: #202020;
padding: 15px;
border-radius: 5px;
.black-tile {
flex: 0 0 80%;
margin: auto;
margin-top: 10px;
}
.update {
margin: auto;
}
}
}
View Compiled
const Updates = ({ updates }) => (
<h4 className="update">Paints<br />{updates}</h4>
);
const Tile = ({ children }) => {
let eventUpdates = React.useRef(0);
return (
<div className="black-tile">
No memo
<Updates updates={eventUpdates.current++} />
{children}
</div>
);
}
const TileMemo = React.memo(({ children }) => {
let updates = React.useRef(0);
return (
<div className="black-tile">
Memo
<Updates updates={updates.current++} />
{children}
</div>
);
}, (prevProps, nextProps) => {
// evaluate whether the props have changed and if
// the component should update
return true;
});
const App = () => {
const updates = React.useRef(0);
const [text, setText] = React.useState('');
return (
<div className="app">
<div className="blue-wrapper">
<input value={text} placeholder="Write something" onChange={(e) => setText(e.target.value)} />
<br />
<Updates updates={updates.current++} />
<Tile>
<Tile>
<Tile />
</Tile>
<Tile />
</Tile>
<TileMemo>
<TileMemo>
<TileMemo />
</TileMemo>
<TileMemo />
</TileMemo>
</div>
</div>
);
};
ReactDOM.render(<App />, document.getElementById('app'));
View Compiled
This Pen doesn't use any external CSS resources.