Frontend/react js(3)
-
React event system
사용법은 일반 HTML 에서 이벤트를 작성하는 것과 유사하지만, 주의해야할 사항 몇가지가 있다. 이벤트 이름은 camelCase 이벤트에 실행할 jscode 가 아닌 함수 형태의 값을 전달한다. -> HTML에서 이벤트를 설정하는 경우에는 큰따움표 안에 실행할 코드를 넣지만, 리액트에서는 함수 형태의 객체를 전달한다. ex) {this.set....}>.. DOM 요소에만 이벤트를 설정할 수 있다. -> 즉 div, button, input , form, span 등 DOM 요소에는 이벤트를 설정할 수 있지만 직접만든 컴포넌트에는 이벤트를 설정할 수 없다. 예를 들어
2019.10.15 -
propTypes
import React, {Component} from 'react'; import PropTypes from 'prop-types' //rcc class MyComponent extends Component { static defaultProps = { name: '기본 이름' }; static propTypes = { name: PropTypes.string, age: PropTypes.number.isRequired }; render() { return ( 안녕하세요, 제 이름은 {this.props.name} 입니다. ); } } export default MyComponent; defaultProps: 해당 prop 이 들어오지 않으면 사용하는 값. propTypes: type 을 명시한다. 아..
2019.10.14 -
js test
test
2019.09.30