https://velopert.com/921


react에서 mutable value는 state에, immutable value는 props에 저장한다고 한다


props는 component를 tag로 사용할 때, attribute를 통해서 세팅되기도 하지만

Component 클래스에 defaultProps라는 attribute(멤버 변수 비슷)를 통해서 세팅할 수도 있다


class App extend React.Component {

    ....

}

App.defaultProps = { ... }


아래와 같이 할수도 있다


class App extend React.Component {

    static defaultProps = { ... }

}


두 코드의 동작방식은 같다. 즉, static keyword를 사용하면 상속되지 않는다


static keyword를 사용하지 않으면 ignore되므로, 주의하자 (error code에서 알려줌)



WRITTEN BY
hojongs
블로그 옮겼습니다 https://hojongs.github.io/