Open12

ts・react関連のメモ

yasushi.kobayashiyasushi.kobayashi

レスポンシブ

yasushi.kobayashiyasushi.kobayashi
import * as React from 'react'
import { useMediaQuery } from 'react-responsive'

export const isPc = () => useMediaQuery({ query: '(min-width: 901px)' })
export const isSp = () => useMediaQuery({ query: '(max-width: 900px)' })

interface Props {
  pc?: React.ReactNode
  sp?: React.ReactNode
}

export const Responsive: React.VFC<Props> = ({ pc, sp }) => {
  const matchPc = isPc()
  const matchSp = isSp()
  return (
    <>
      {matchPc && <>{pc}</>}
      {matchSp && <>{sp}</>}
    </>
  )
}
yasushi.kobayashiyasushi.kobayashi
export const sp = 900
export const spStyle = `@media (max-width: ${sp}px)`

const Content = styled('div')`
  width: 860px;

  ${spStyle} {
    width: 100%;
  }
`
yasushi.kobayashiyasushi.kobayashi

不要なts検出
npx ts-unused-exports tsconfig.json | grep -v "pages" | grep -v "story"