갈푸라떼
갈푸라떼는 개발중
갈푸라떼
전체 방문자
오늘
어제
  • 분류 전체보기 (232)
    • CS (0)
      • CSinfo (0)
    • Frontend (15)
      • HTML,CSS (1)
      • Javascript (2)
      • React (0)
      • React Hook (12)
    • Backend (0)
      • Python (0)
      • Node.js (0)
      • php (0)
    • DB (2)
      • MySQL (2)
      • BigQuery (0)
      • Mongodb (0)
    • Study (186)
      • JavaScript (72)
      • JavaScript(Clean code) (50)
      • Node.js (11)
      • HTML,CSS (13)
      • React (30)
      • TypeScript (10)
      • React-Native (0)
    • Error (2)
      • error (2)
    • Git (22)
      • Git (22)
    • Help Coding (4)
      • Useful websites (3)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • Github

공지사항

인기 글

태그

  • 원시타입
  • 정적 레벨
  • 인터프리터
  • 함수
  • 심볼
  • Babel
  • 이터러블
  • class
  • 실행 컨텍스트
  • SPREAD
  • 객체타입
  • nodemon
  • Arrow
  • 상속
  • this
  • 네이밍
  • function
  • 자바스크립트엔진
  • structure
  • 스코프 체인
  • 컴파일러
  • 프로토타입
  • prototype
  • 오버라이딩
  • 싱글스레드
  • ECMAScript
  • 렉시컬 환경
  • PM2
  • symbol
  • 호이스팅

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
갈푸라떼

갈푸라떼는 개발중

[React_study] useMatch()
Study/React

[React_study] useMatch()

2022. 7. 24. 20:46

* useMatch()

  • 현재 위치를 기준으로 지정된 경로에 대한 일치 데이터를 반환합니다.
  • useMatch()의 인자로 url을 넘기어 해당 url과 일치할 경우 url의 정보를 반환하고 일치하기 않을 경우 null을 반환한다.

* useMatch() 활용 예시코드

import { useMatch } from 'react-router-dom';

const priceMatch = useMatch("/:coinId/price");
const chartMatch = useMatch("/:coinId/chart");

const Tab = styled.span<{ isActive: boolean }>`
  color: ${(props) => props.isActive ? "white" : "black"};
`;

 <Tabs>
    <Tab isActive={chartMatch !== null}>
      <Link to={`/${coinId}/chart`}>Chart</Link>
    </Tab>
    <Tab isActive={priceMatch !== null}>
      <Link to={`/${coinId}/price`}>Price</Link>
    </Tab>
</Tabs>
  • useMatch를 이용해 2개의 url을 인자로 받는다.
  • url이 일치할 경우 isActive는 true가 되므로 styled-components의 props에 의해서 white가 된다.
  • 해당 기능을 이용해 현재 클릭중인 url의 색상을 변경해 강조해 줄 수 있다.

'Study > React' 카테고리의 다른 글

[React_study] styled-components를 이용한 dark/light모드  (0) 2022.07.20
[React_study] 터미널 / 브라우저 콘솔창에 warning  (0) 2022.06.20
[React_study] reset css 하는 방법 + npm으로 설치  (0) 2022.06.18
[React_study] Redux state가 object/array일 경우 변경 방법  (0) 2022.06.15
[React_study] Redux store의 state 변경  (0) 2022.06.12
    'Study/React' 카테고리의 다른 글
    • [React_study] styled-components를 이용한 dark/light모드
    • [React_study] 터미널 / 브라우저 콘솔창에 warning
    • [React_study] reset css 하는 방법 + npm으로 설치
    • [React_study] Redux state가 object/array일 경우 변경 방법
    갈푸라떼
    갈푸라떼

    티스토리툴바