with redux to have better state management
“virtual”, representation of a UI is kept in memory and synced with the “real” DOM by a library such as ReactDOM
Set of instructions React follows when creating and updating User Interface
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
React.createElement('h1', null, 'Heading'),
document.getElementById('react-root')
);
<body>
<div id="react-root">
</div>
</body>
const todoList = React.createClass({
displayName: 'TodoListItems',
render() {
return React.createElement('ul', {className: 'Todos'},
React.createElement('li', null, 'Go to grocery shop'),
React.createElement('li', null, 'Buy tequilla'),
);
}
});
ReactDOM.render(
React.createElement('TodoListItems', null, null),
document.getElementById('react-root')
)const TodoItemList extends React.Component {
render() {
const {items} = this.props;
return React.createElement('ul', {className: 'Todos'},
items.map((item, i) => React.createElement('li', { key: i }, item)) }
);
}
}
const todos = ['Go to Grocery Shop', 'Buy fruits', 'Get back home safely']l
ReactDOM.render(
React.createElement('TodoListItems', {item: todos }, null),
document.getElementById('react-root')
)const TodoListItems = (props) => {
return React.createElement('ul', {className: 'Todos'},
React.createElement('li', null, 'Go to grocery shop'),
React.createElement('li', null, 'Buy tequilla'),
);
}Concise syntax for creating complex Dom Trees
<div className="container">
<h1 className="page-title"> Todos for {this.props.username}
<h3 className="sub-title"> { this.getSubtitle() } </h3>
<ul>
{ this.props.items.map((item, i) => { return (<li key={i}> { item } </li>) }) }
</ul>
<a href="#" dataAttrs="data-attr-value" onClick=> link </a>
</div>
const {_title} = this.refs.
const element = _this.current;
<h1 ref="_title"> Title </h1>
<parent sendToChild="data" reciveFromChild={callbackFn} />
<child onClick={(e) => {this.props.reciveFromChild(data)> { this.props.sendToChild } </child>
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
title : "Hello World"
}
}
changeTitle = (e) => {
this.setState({
title: 'New title'
});
};
render() {
const {title} = this.state;
return(
<>
<h1> {title} </h1>
<button onClick={this.changeTitle} > Change Title </button>
</>
);
}
}componentDidCatch
componentWillMount
UNSAFE_componentWillMount
componentWillUpdate
UNSAFE_componentWillUpdate