TIL react review 2018-05-31
31 May 2018 |복기
- component를 만들었을 때 include하는 css의 파일 경로를 제대로 설정하지 않으면 component가 export되지 않아 사용하는 측에서 찾을 수 없다고 에러를 발생 시킨다
- stx에서 img 태그를 줄때는 alt를 설정해 줘야 한다 경고 발생한다
- component에서 넘겨받은 값의 type을 체크할 때 prop-types를 사용한다
propTypes 사용
설치 $ npm install –save prop-types
import PropTypes from 'prop-types';
class MyComponent extends React.Component {
render() {
// This must be exactly one element or it will warn.
const children = this.props.children;
return (
<div>
{children}
</div>
);
}
}
MyComponent.propTypes = {
children: PropTypes.element.isRequired
};
- state 사용하기
- componentDidMount
- fetch
- dummy component: parameter를 넘길 때 {}객체화 시켜서 넘겨야 한다
Comments