Babel ReactJS Element DataFlow Component State
Babel ReactJS Element DataFlow Component State
Lecture 11
Fall 2020 – November 4, 2020
Tonight’s Agenda
• ReactJS Introduction / Fundamentals
• Elements, Components, State, Props
• Component Lifecycle
4
React JS
• Created at Facebook by software engineer Jordan Walke
• An early prototype in 2011 (FaxJS) shipped as a search element on Facebook. Jordan then
worked on a prototype for the hard to manage Facebook Ads which became react.
• Deployed in newsfeed in 2011 and instagram.com in 2012 after Facebook acquired them.
• Open sourced at JSConf US May 2013
<Container>
<NavBar />
<Header />
8
React JS – Unidirectional Dataflow
• In a React app data flows from parent component to child component
• Data is passed as props to the component and the props are immutable
• If a component needs to save data/state it needs to do that in itself or get that data as props
from a parent
11
React JS – React Elements
• Fundamental object and concept in React apps
• A React element is a JavaScript object representation that describes how you would like it to
appear on the screen. This is a JavaScript representation of a DOM Node.
• Use React.createElement() to create an element
13
React JS - Components
• A component is a function or a Class which optionally accepts input and
returns a React element.
• React components can be function based or class based
• React component names should start with a capital letter
Or
https://reactjs.org/docs/react-without-jsx.html
17
React JS - Components
• Components can use other components
Class HelloHeader extends React.Component {
render() {
return <h1>Hello World!</h1>;
}
}
searchHandler(e){
console.log(e);
}
}
20
React JS – State
• State is place we can store data in a component and change the data to see a reflection in the UI.
• Must add a constructor to your class and initialize the state there.
• Try to make the state as simple as possible and keep as many components stateless as possible. If you
have many components that need state you should make a parent component that has the state in it
and pass it down through props.
21
React JS – State
• Do not try to modify the state object directly
// Wrong
this.state.comment = ‘Hello’;
// Correct
25
React JS Resources
• https://reactjs.org/
• https://facebook.github.io/react-native/
• https://babeljs.io/
• https://tylermcginnis.com/
26
Assignments
28