This document provides an overview of React including its core concepts and benefits. React is a declarative, efficient, and flexible JavaScript library for building user interfaces. It allows building of reusable UI components, uses a virtual DOM for better performance, and can be used to build mobile apps using React Native. Code for Fukuoka is an event on August 1st to learn React and how to contribute to open source projects.
9. Declarative
•
•
•
•
(+ 1 2 3 4 5) ;15
var sum = function(arr){
var sum=0;
for(var i=0; i < arr.length; i++){
sum += arr[i];
}
return sum;
}
var arr = [1, 2, 3, 4, 5];
console.log( sum(arr) ); // 15
sum [1,2,3,4,5] --15
10. https://tylermcginnis.com/imperative-vs-declarative-programming/
function double (arr) {
let results = []
for (let i = 0; i < arr.length; i++){
results.push(arr[i] * 2)
}
return results
}
function double (arr) {
return arr.map((item) => item * 2)
}
function add (arr) {
let result = 0
for (let i = 0; i < arr.length; i++){
result += arr[i]
}
return result
}
function add (arr) {
return arr.reduce((prev, current) => prev + current, 0)
}
$("#btn").click(function() {
$(this).toggleClass("highlight")
$(this).text() === 'Add Highlight'
? $(this).text('Remove Highlight')
: $(this).text('Add Highlight')
})
<Btn
onToggleHighlight={this.handleToggleHighlight}
highlight={this.state.highlight}>
{this.state.buttonText}
</Btn>
11. • CBD: Component-based development
• separation of
concerns
•
•
• Web Web
•
•
https://en.wikipedia.org/wiki/Component-based_software_engineering
https://medium.com/@dan.shapiro1210/understanding-component-based-architecture-3ff48ec0c238
15. ES2015 ECMAScript2015
• ES6 6th Edition
•
let
let name = 'taro';
name = 'hanako'
const
const name = 'taro';
name = 'hanako'; // error
class
class Person {
constructor(name){
this.name = name;
}
}
const person = new Person('taro')
const fn = (name) =>{
return console.log(name);
}
const arr = ['a', 'b', 'c'];
const arr2 = [...arr];
console.log(arr === arr2); // false
const name = 'taro';
console.log(`My name is ${name}.`); // My name is taro.
https://babeljs.io/docs/en/learn/
17. DOM
• DOM ReactDOM
DOM
• DOM
• DOM DOM
Key
https://reactjs.org/docs/faq-internals.html
{todos.map((todo, index) =>
<Todo
{...todo}
key={index}
/>
)}
https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318
{todos.map((todo) =>
<Todo {...todo}
key={todo.id} />
)}
var shortid = require('shortid');
function createNewTodo(text) {
return {
completed: false,
id: shortid.generate(),
text
}
}
ID
shortid
ID
ID todoCounter = 1;
function createNewTodo(text) {
return {
completed: false,
id: todoCounter++,
text
}
}