<Wontae />
Navigate back to the homepage

westargram-react 후기

Wontae Jeong
September 11th, 2020 · 1 min read
westagram

🙌 소개

  • React.js를 이용한 인스타그램 클론
  • CRA(create-react-app)를 사용한 초기 세팅
  • Git을 사용한 팀 협업 과정
  • MockData를 이용하여 UI 구현 후 componentDidMount()fetch()를 이용해 백엔드와의 통신
  • Code refactoring

🎉 프로젝트 기간

  • 2020.08.31 ~ 2020.09.11

🛸 사용 기술

React
JavaScript
SASS
Git

🚀 구현 기능

  로그인 페이지

login page

login page

  • 슬라이드 fade-in / fade out
  • 유효성 검사 확인
  • withRouterHOC 로 페이지 이동 구현 - this.props.history.push('/signup')
  • 서버와의 통신 fetch()
  • media query를 이용한 반응형 구현
  • MockDatamap()을 활용해 sitemap 구현

  메인 페이지

login page

login page

  • 댓글 추가 / 삭제 / 좋아요 기능
  • 유저 검색 기능
  • 유저 아이콘 클릭 시 서브 메뉴 토글
  • Mockdatamap()을 활용하여 컴포넌트 활용
  • media query를 이용한 반응형 구현

✍ 기억하고 싶은 코드

1constructor() {
2 super();
3 this.state = {
4 isChecked: false,
5 id: '',
6 password: '',
7 };
8 }
9
10 goToMain = () => {
11 const { isChecked, id, password } = this.state;
12
13 isChecked &&
14 fetch('http://3.34.133.239:8000/account/signin', {
15 method: 'POST',
16 body: JSON.stringify({
17 email: id,
18 password: password,
19 }),
20 })
21 .then((response) => response.json())
22 .then((result) => {
23 if (result.Authorization) {
24 localStorage.setItem('token', result.Authorization);
25 this.props.history.push('/main-wontae');
26 } else if (result.message === 'UNAUTHORIZED') {
27 alert('이메일 / 비밀번호를 확인해주세요');
28 }
29 });
30 };
31
32 saveData = (e) => {
33 const { name, value } = e.target;
34 this.setState(
35 {
36 [name]: value,
37 },
38 this.checkValidation
39 );
40
41 if (e.key === 'Enter') {
42 this.goToMain();
43 }
44 };
45
46 checkValidation = () => {
47 const { id, password } = this.state;
48 const isChecked = id.includes('@') && password.length >= 5;
49 this.setState({
50 isChecked,
51 });
52 };
53
54 render() {
55 retrun (
56 ...
57 <div onKeyUp={this.saveData} className="form">
58 <input
59 name="id"
60 type="text"
61 placeholder="전화번호, 사용자 이름 또는 이메일"
62 />
63 <input name="password" type="password" placeholder="비밀번호" />
64 <button
65 type="submit"
66 className={isChecked ? 'isActive' : null}
67 onClick={this.goToMain}
68 >
69 로그인
70 </button>
71 </div>
72 ...
73 )
74 }
  • 비구조화 할당으로 가독성 높이기
  • fetch() 함수로 서버와의 데이터 통신
  • className의 동적인 사용
  • 명확한 함수, 변수, 클래스 이름
  • Input의 name과 계산된 속성명(computed property names) 이용하기

More articles from Wontae Jeong

DOM

DOM(Document Object Model)이란

August 23rd, 2020 · 1 min read

for, for...in, for...of, forEach()

자바스크립트는 왜 이러한 반복문의 방법을 다양하게 갖고 있는 것일까?

August 23rd, 2020 · 1 min read
© 2020 Wontae Jeong
Link to $https://github.com/wontaeziaLink to $https://instagram.com/wontaeziaLink to $https://www.youtube.com/channel/UC6xNhtj5VHgxvAnp0x8tmOw?view_as=subscriber