node.js

kodaeyong·2021년 4월 14일

component: property[prop]= value

설치

npm i prop-types
: 내가 전달받은 props가 내가 원하는 props인지를 확인해주는 것

설치되있는지 확인
package.json에서 prop-types 있는지 확인

state(클래스 컴포넌트)

동적 데이터와 함께 작업할 때 만들어짐. 변하는 데이터, 존재하지 않는 데이터
state는 object 바꾸고 싶은 데이터를 state 안에 넣어라
클래스 이기 때문에 {this.state.count}

컴포넌트가 state가 필요 없을 경우에는 이게 class 컴포넌트가 될 필요가 없다.... 함수형 컴포넌트로 사용

setState 사용

add = () => {
	this.setState({ count: 1 });
    };

componentDidUpdate()

componentDidUpdate() {
	console.log("I just updated");
   }
   업데이트될때 호출


setState를 호출하면, 컴포넌트를 호출하고, 먼저 render를 호출한 다음 업데이트가 완료되었다고 말하면 componentDidUpdate가 실행된다.

conponentWillUnmount()

컴포넌트를 떠날때 호출

conponentWillUnmount(){
    console.log("Goodbye, cruel world");
  }

mount: 생겨나는 것.
isLoading: true

componentDidMount()

처음에 render를 하면 호출되는 life cycle method

fetch() Axios

npm install axios
시간이 조금 걸린다... await 넣기

getMovies = async () => {
	const movies = await axios.get("https://....")
    };

img alt

<img src={poster} alt={title} title={title} />

alt는 이미지에 올렸을때 나오는 것

className

HTML
<section class="container">

React
<section className="container">

0개의 댓글