UMRR Notes”
Section 1: Let’s Dive In!
10. Javascript Module Systems
- Make new cra
- delete everything from src
- make new index.html
- import React and ReactDOM libraries
- create a react component
- Take the react component and show it on the screen
Section 2: Building Content with JSX
Section 3: Communicating with Props
Section 4: Structuring Apps with Class-Based Components
Section 5: State in React Components
import React from 'react';
import ReactDOM from 'react-dom';
class App extends React.Component {
constructor(props){
super(props);
this.state = {lat: null, errorMessage: null}
window.navigator.geolocation.getCurrentPosition(
// success callback
position => this.setState({ lat: position.coords.latitude }),
// error callback
err => this.setState({ errorMessage: err.message})
)
}
render(){
if (this.state.errorMessage && !this.state.lat) {
return(<div> Latitude: {this.state.errorMessage} </div>)
}
if (!this.state.errorMessage && this.state.lat) {
return(<div> Error: {this.state.lat} </div>)
}
return(<div> Loading! </div>)
}
}
ReactDOM.render(<App />, document.querySelector("#root"))
THREE THINGS:
Lifecycle methods! Component re-renders when state is updated
- ComponentDidMount (runs once, when component is MOUNTED onto the dom)
- ComponentDidUpdate (runs once component re-renders ** AFTER STATE HAS BEEN UPDATED!!)
- ComponentWillUnMount
Section 6: Understanding Lifecycle Methods
61:
GOAL: Move code from constructor to ComponentDidMount