let func = (a) => {} // parentheses optional with one parameter
let func = (a, b, c) => {} // parentheses required with multiple parameters
let str = `Release Date: ${date}`let str = `Release Date: ${date}`
let func = (a, b, c) => a + b + c // curly brackets must be omitted
let obj = {
a,
b,
}
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('root')
);
const element = <h1>Hello, world!</h1>;
ReactDOM.render( element, document.getElementById(‘root’) );
- Example of using JSX inside if statement:
function getGreeting(user) { if (user) { return <h1>Hello, {formatName(user)}!</h1>; } return <h1>Hello, Stranger.</h1>; }
- Safe to embed user input with JSX:
const title = response.potentiallyMaliciousInput; // This is safe: const element = <h1>{title}</h1>;
- React DOM escapes values embedded in JSX before rendering them.
- Example of rendering a react element into a root DOM node:
const element = <h1>Hello, world</h1>; ReactDOM.render(element, document.getElementById(‘root’));
- React elements are immutable.
- React will only update what is necessary.
- Example of rendering a component:
function Welcome(props) { return <h1>Hello, {props.name}</h1>; }
const element =
- Name props from the component’s own point of view rather than the context in which it is being used.
- State is similar to props, but it is private and fully controlled by the component.
- Lifecycle methods: componentDidMount() and componentDidMount().
- Example of handling event in React:
<button onClick={activateLasers}> Activate Lasers </button> ```