티스토리 뷰
React
프로젝트 시작 (C:\react 디렉토리에서 실행했음)
npm i create-react-app
npx create-react-app hello-react
cd hello-react
npm start
리액트 라이브러리 (page 5)
1. 파일들을 C:\react\hello-world 에 저장
https://unpkg.com/react@16.12.0/umd/react.development.js
https://unpkg.com/react@16.12.0/umd/react.production.min.js
https://unpkg.com/react-dom@16.12.0/umd/react-dom.development.js
https://unpkg.com/react-dom@16.12.0/umd/react-dom.production.min.js
- development => 개발 환경에서 사용하는 파일
- production => 실행(배포) 환경에서 사용하는 파일
- react => 플랫폼 구분 없이 공통으로 사용하는 파일 (리액트 코어)
- react-dom => 웹 환경에서 사용되는 파일
2. 리액트로 좋아요 토글을 구현
2-1. jQuery로 좋아요 토글을 구현한다면
3. React 좋아요 버튼을 여러개 구현
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <script> class LikeButton extends React.Component { constructor(props) { super(props); this.state = { liked: false }; } render() { const text = this.state.liked ? '좋아요 취소' : '좋아요'; return React.createElement( 'button', { onClick: () => { console.log(this.state.liked); this.setState({ liked: !this.state.liked }); } }, text, ); } } ReactDOM.render(React.createElement(LikeButton), document.querySelector('#react-root1')); ReactDOM.render(React.createElement(LikeButton), document.querySelector('#react-root2')); ReactDOM.render(React.createElement(LikeButton), document.querySelector('#react-root3')); </script> | cs |
3-1. jQuery 좋아요 버튼을 여러개 구현
4. React 증가, 감소 버튼 구현
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | class LikeButton extends React.Component { constructor(props) { super(props); this.state = { liked: false }; } render() { const text = this.state.liked ? '좋아요 취소' : '좋아요'; return React.createElement( 'button', { onClick: () => this.setState({ liked: !this.state.liked }) }, text, ); } } // P9 코드1-6 참조 class Container extends React.Component { constructor(props) { super(props); this.state = { count: 0 }; } render() { return ( <div> <likeButton /> <div style={{ marginTop: 20 }}> <span>현재 카운트: </span> <span>{this.state.count}</span> <button onClick={() => this.setState({count: this.state.count + 1})}>증가</button> <button onClick={() => this.setState({count: this.state.count + 1})}>감소</button> </div> </div> ) } } ReactDOM.render( React.createElement(Container), document.querySelector('#react-root') ); | cs |
Babel
JSX -> ES5 컴파일러
npm install @babel/core @babel/cli @babel/preset-react
npx babel --watch src --out-dir . --presets @babel/preset-react
Webpack
fashion
'활동 > 교육과정 중 기록' 카테고리의 다른 글
200206 React (0) | 2020.02.06 |
---|---|
200205 React, JavaScript (0) | 2020.02.05 |
200129 JavaScript, jQuery (0) | 2020.01.29 |
200128 JavaScript (0) | 2020.01.28 |
200109 OpenStack (0) | 2020.01.09 |
- Total
- Today
- Yesterday
- 운영체제
- #패스트캠퍼스 #프로그래밍대학생서포터즈 #올인원패키지 #컴퓨터공학 #성공하는프로그래밍공부법
- 자료구조
- 코딩 면접
- 컴퓨터공학
- 개발자 취업
- 올인원 패키지
- c언어
- Fast Campus
- 프로그래밍 온라인 강의
- 패스트캠퍼스
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |