React

by STHayden

HTML

<div id="app"></div>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
}

li {
  margin: 8px 0;
}

h2 {
  font-weight: bold;
  margin-bottom: 15px;
}

.done {
  color: rgba(0, 0, 0, 0.3);
  text-decoration: line-through;
}

input {
  margin-right: 5px;
}

React

const Cotainer = () => {
	const [count, setCount] = React.useState(0)

	return (
  <div onClick={() => setCount(a => a+1)}>
  	<Item1 count={count}>
  	  <Item2Memo>c</Item2Memo>
  	</Item1>
    </div>
  )
}

const Item1 = (props) => {
 console.log('render - item1')
 return (
 	<div>
    <h1>item 1 - {props.count}</h1>
 	  {props.children}
 	</div>
 );
}

const Item2 = (props) => {
 console.log('render - item2')
 return (
 	<div  >
    <h2>item 2</h2>
 	  {props.children}
 	</div>
 );
}

const Item2Memo = React.memo(Item2)

ReactDOM.render(<Cotainer />, document.querySelector("#app"))