Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestions for reducing the package size #5

Open
yusufseyrek opened this issue May 16, 2023 · 0 comments
Open

Suggestions for reducing the package size #5

yusufseyrek opened this issue May 16, 2023 · 0 comments

Comments

@yusufseyrek
Copy link
Contributor

In order to reduce bundle size of this project which is potentially causing inflated bundle sizes on its dependents, I suggest removal of some packages from dependencies and use native solutions instead:

  • Replace react-device-detect with a custom hook. Example:
import React from "react"

export default function useDeviceDetect() {
  const [isMobile, setMobile] = React.useState(false)
  const [isDesktop, setDesktop] = React.useState(false)
  const [isAndroid, setAndroid] = React.useState(false)
  const [isIOS, setIOS] = React.useState(false)

  React.useEffect(() => {
    const userAgent =
      typeof window.navigator === "undefined" ? "" : navigator.userAgent
    const mobile = Boolean(
      userAgent.match(
        /Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile|WPDesktop/i
      )
    )
    const android = Boolean(userAgent.match(/Android/i))
    const ios = Boolean(userAgent.match(/iPhone|iPad|iPod/i))

    setMobile(mobile)
    setDesktop(!mobile)
    setAndroid(android)
    setIOS(ios)
  }, [])

  return { isMobile, isDesktop, isAndroid, isIOS }
}

  • Replace axios with native fetch function
  • Replace react-modal with a native React modal solution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant