처음이라 재밌었다.
📙 열품타 7hour
👍 TIL 잘 정리
👎 늦게 일어남
1) 강의
2) 부족한 부분 복습/ 드릴다운
3) 1)번 복기 및 2)번 업데이트
4) 3)번 기반으로 창작
5) 반복
노마드코더 "ReactJS로 영화 웹 서비스 만들기" 100% 수강
수강 후 복기하기
Udemy에서 Javascript 강좌 수강하기
개발자 유튜브 통해서 공부 방향 및 팁 배우기
github 만들고 git push 해보기
[프로그램 설치 확인 방법]
터미널에서 프로그램명 -v 입력 + 엔터 (v:version)
예) node.JS 설치 확인법 : node -v
node.Js를 설치하면 npm이 자동으로 설치된다.
준비물: node.Js, npm, npx, git, VSC, homebrew
React 배우기 위해서는 Html+CSS+Js 지식 필요
function, variable, class, div, span, flexbox, display block, background color, return, argument, constants, let, array, object에 대한 개념이 필요하다.
페이스북이 관리.
에어비앤비. npm. 넷플릭스. 스포티파이. 슬랙 등이 사용.
프론트엔드 64%가 사용 (stateofjs.com에서 확인 가능)
리액트는 자바스크립트인 경우 많아서 리액트 사라져도 자바스크립트 개발 지식 남음
여기서 react 패키지를 통째로 다운받을 수 있다
https://github.com/facebook/create-react-app
패키지 파일을 만들어주는 명령어:
npx create-react-app movie_app_2021
terminal-npm start:
developement server을 시작해서 브라우저에서 보며 개발할 수 있다.
terminal에서 git init 실행
git add 입력
git commit -m "제목"
git push origin master
React: javascript로 만들고 html로 넣는다.
virtual DOM: virtual document object model
componant는 html을 반환하는 함수 (function returns html)
javascript와 html 사이의 조합을 jsx라고 한다
import React from 'react':
component 작성할 때마다 써줘야 함
react application은 App이라는 하나의 component만 rendering
따라서 App(main component)에 모든 component를 넣어줘야 한다
./: 같은 directory라는 의미
재사용 가능한 component: component를 계속 반복해서 사용할 수 있다
<Food fav="orange" />
food=component, fav=property, orange=value
food component에 정보를 보내는 법:
component의 property를 function component의 argument(인자)로 넣는다
function Food({fav}) = function Food(props.fav)
동적 데이터
component는 대문자로 시작해야 한다
웹사이트에 동적 데이터를 추가하는 법
map은 function을 취해서 array의 각 item에 적용한다
friends.map(function(friend){
return friend +"💖";})
react는 각기 다른 element를 가져야 한다
image element는 alt prop이 있어야 한다(for blind people)
father component로부터 property를 제대로 전달받고 있는지 확인하는 법
: npm i prop-types 설치 (i=install)
proptypes 사용법
Food.propTypes = {
name: PropTypes.string.isRequired,
picture: PropTypes.string.isRequired,
rating: PropTypes.number.isRequired,
}
import React from "react";
import PropTypes from "prop-types";
function Food({ name, picture, rating }) {
return (
<div>
<h2>I like {name}</h2>
<h4>{rating}/5.0</h4>
<img src={picture} alt={name} />
</div>
);
}
Food.propTypes = {
name: PropTypes.string.isRequired,
picture: PropTypes.string.isRequired,
rating: PropTypes.number.isRequired,
}
const foodILike = [
{
id: 1,
name: "Orange",
image:
"https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.allfreschgroup.com%2Fwp-content%2Fuploads%2F2017%2F01%2FValencia-Orange.png&f=1&nofb=1",
rating: 5.0
}
];
function App() {
return (
<div>
{foodILike.map(dish => (
<Food key={dish.id} name={dish.name} picture={dish.image} rating={dish.rating} />
))}
</div>
);
}
export default App;
React.component는 함수가 아니기 때문에 return하지 않는다.
대신 render method를 가지고 있음
class App extends React.component -> React.component에서 extend 했기 때문에 class App에도 render method가 생긴다 ->
react는 자동으로 class component의 render method를 실행한다
function component가 아닌 class component를 사용하는 이유
: class component는 state다.
state는 object고 component의 data를 넣을 공간이 있고 이 data는 변한다
import React from "react";
import PropTypes from "prop-types";
class App extends React.Component{
state = {
count: 0
};
add = () => {
console.log("add");
};
minus = () => {
console.log("minus");
};
render() {
return (
<div>
<h1> The number is: {this.state.count} </h1>
<button onClick={this.add}>Add</button>
<button onClick={this.minus}>Minus</button>
</div>
);
}
}
export default App;
add = () => {
this.setState(current => ({count:current.count +1}));
};
setState를 호출할 때마다 react는 새로운 state와 함께 render function을 호출한다 (다시 render한다)