let url = "https://www.googleapis.com/youtube/v3/search?";
let obj = {
q: query,
maxmaxResults: max,
key: key,
part: "snippet",
type: "video"
};
for (let key in obj) {
url += key + "=" + obj[key] + "&";
}
// search? ๋ค ์ฃผ์๋ ( key=obj[key]& ) ์ด๋ ๊ฒ ์์ฑ
๋น๋๊ธฐ์ ์ผ์ ํ ๊ฒฝ์ฐ componentdidMount์์ ์คํ
ComponentDidMount
componentDidMount() { // ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฐ๋: D3, masonry, etc // ์ปดํฌ๋ํธ์์ ํ์ํ ๋ฐ์ดํฐ ์์ฒญ: Ajax, GraphQL, etc // DOM ์ ๊ด๋ จ๋ ์์ : ์คํฌ๋กค ์ค์ , ํฌ๊ธฐ ์ฝ์ด์ค๊ธฐ ๋ฑ }
import React, { Component } from 'react';
class Counter extends Component {
state = {
number: 0
}
constructor(props) {
super(props);
console.log('constructor');
}
componentWillMount() {
console.log('componentWillMount (deprecated)');
}
componentDidMount() {
console.log('componentDidMount');
}
shouldComponentUpdate(nextProps, nextState) {
// 5 ์ ๋ฐฐ์๋ผ๋ฉด ๋ฆฌ๋ ๋๋ง ํ์ง ์์
console.log('shouldComponentUpdate');
if (nextState.number % 5 === 0) return false;
return true;
}
componentWillUpdate(nextProps, nextState) {
console.log('componentWillUpdate');
}
componentDidUpdate(prevProps, prevState) {
console.log('componentDidUpdate');
}
handleIncrease = () => {
const { number } = this.state;
this.setState({
number: number + 1
});
}
handleDecrease = () => {
this.setState(
({ number }) => ({
number: number - 1
})
);
}
render() {
console.log('render');
return (
<div>
<h1>์นด์ดํฐ</h1>
<div>๊ฐ: {this.state.number}</div>
<button onClick={this.handleIncrease}>+</button>
<button onClick={this.handleDecrease}>-</button>
</div>
);
}
}
export default Counter;
์ฐธ๊ณ ๋ฌธ์ : React ๊ณต์ ๋ฌธ์
react ์๋ช ์ฃผ๊ธฐ๋ ํ์ ๋ฒ์ ์์๋ ๋ค๋ฆ ๋๋ค.
https://ko.reactjs.org/docs/react-component.html ๊ณต์๋ฌธ์
https://www.w3schools.com/react/react_lifecycle.asp ๋ฅผ ๋ณด๋ฉด ์ข์ต๋๋ค ใ ใ