Course Curriculum
@makzan
Getting started
https://reactjs.org/docs/thinking-in-react.html
ReactDOM.render(
React.createElement("h1", null, "Hello, world!"),
document.getElementById('root')
);
Creating our first ReactDOM render
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('root')
);
Creating our first ReactDOM render
It is sugar syntax.
JSX is indeed `createElement` function with XML-like syntax.
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
*JSX is just JavaScript
const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) =>
<li>{number}</li>
);
const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) =>
<li key={number.toString()}>
{number}
</li>
);
Don’t forget the key.
What’s the difference?
When to choose which?
https://reactjs.org/docs/faq-state.html#what-is-the-difference-between-state-and-props
props get passed to the component (similar to function parameters) whereas state is managed within the component (similar to variables declared within a function).
https://reactjs.org/docs/components-and-props.html#props-are-read-only
All React components must act like pure functions with respect to their props.
https://reactjs.org/docs/react-component.html#the-component-lifecycle
shouldComponentUpdate
JavaScript StyleSheet