React(9)
-
react-router-dom Switch component, NotFound
Switch component 작성방법 1. 좁은 범위의 컴포넌트부터 넓은 범위의 컴포넌트 순서로 작성한다. 다음 2. Root경로에는 exact를 추가 3. NotFound는 제일 아래
2021.07.27 -
Dynamic Routing에서 props 가져올 때
https://localhost:3000/about?name=mark 에서 mark를 가져오고 싶을 때 1. URLSearchParams 사용(브라우저에 따라 동작 안할 수 있음) const searchParams = props.loacation.search; const obj = new URLSearchParams(searchParams); console.log(obj.get("name")); 2. query-string 사용 설치 npm i query-string -S 사용법 const query = queryString.parse(searchParams); console.log(query.name);
2021.07.27 -
React State Handling
React에서 state을 변경할 때는 setState를 이용해야 rendering됨 componentDidMount() { setTimeout(() => { this.state.count = this.state.count + 1; }, 1000); } 동작X componentDidMount() { setTimeout(() => { this.setState({ count: this.state.count + 1; }); }, 1000); } 동작O
2021.07.24