reading-notes

React 1

ES6 Overview

React

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 = ; ReactDOM.render( element, document.getElementById(‘root’) );

- 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> ```