Slides: goo.gl/bPBbiy
Breakfast
React Introduction
Fika
Examples
Coding! & Lunch
"A JavaScript library for building user interfaces"
ES6 usage is rampant in our examples
const alwaysTrue = function () {
return true;
}
// Can be written in ES6 as
const alwaysTrue = () => true;
Which is great in callback functions
onClick(function(event) {
return event.target.value;
});
// Becomes this when using arrow functions
onClick(event => event.taget.value);
(() =>{
var foo = 1
let bar = 1 // Block scoped
if (true){
var foo = 2 // Same variable
let bar = 2 // Dif. scope
}
console.log('foo = ' + foo)
console.log('bar = ' + bar)
})()
//Returns
foo = 2
bar = 1
const x = 123 //Cannot be reassigned & block scoped
function Boo() {}; // Is hoisted
class Far {}; // Has a constructor & is not hoisted
var object = new Far() // Instantiate a class object
Create your first component
Use props to pass data
Each component can have its own state
State can be passed down to other components
const Hello = ({you}) => (Hello, {you}!)
Stateful (class)
class Hello extends React.Component {
constructor(props) {
super(props);
}
render() {
return(
Hello {props}
)
}
}
Use state to make application dynamic
Could be on paper, whiteboard or a HTML prototype
Which components has a shared state?
"Data down, actions up"
React and Fetch