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

[bug]: Can't find use-mobile hook in shadcn doc #6133

Open
2 tasks done
ardevik opened this issue Dec 19, 2024 · 6 comments
Open
2 tasks done

[bug]: Can't find use-mobile hook in shadcn doc #6133

ardevik opened this issue Dec 19, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@ardevik
Copy link

ardevik commented Dec 19, 2024

Describe the bug

Because restricted firewall in my company, I can't use the cli for adding components because it point to external registry, so I'm using manual installation for sidebar component and adding requirement one by one. Until I want add the @/components/hooks/use-mobile but can't find the example

Affected component/components

Sidebar

How to reproduce

  1. Go to shadcn website
  2. Add Sidebar with Manual Installation

Codesandbox/StackBlitz link

No response

Logs

No response

System Info

Chrome

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@ardevik ardevik added the bug Something isn't working label Dec 19, 2024
@akshay-nm
Copy link

akshay-nm commented Dec 21, 2024

the import generated in the sidebar.tsx (/components/sidebar.tsx) is

import { useIsMobile } from "@/components/hooks/use-mobile"

this hook is not installed via installation command. Any ideas where I get this?

@i-am-henri
Copy link

@akshay-nm You can get this hook via the repo:
{0BE091C1-FD1A-47EC-A3E4-FF99D8F60474}

This is the hook:

import * as React from "react"

const MOBILE_BREAKPOINT = 768

export function useIsMobile() {
  const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)

  React.useEffect(() => {
    const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
    const onChange = () => {
      setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
    }
    mql.addEventListener("change", onChange)
    setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
    return () => mql.removeEventListener("change", onChange)
  }, [])

  return !!isMobile
}

@akshay-nm
Copy link

akshay-nm commented Dec 22, 2024

i triednpx shadcn@latest add sidebar-01 as suggested here: https://ui.shadcn.com/blocks/sidebar

It worked, but one issue is, the shadcn add command overwrites the lib/utils.tsx (not related to this issue).
I had a bunch of functions in that file, and thanks to git i was able to revert changes in that file.

@DemaPy
Copy link

DemaPy commented Dec 28, 2024

PR created to close issue.

@DemaPy
Copy link

DemaPy commented Dec 28, 2024

@ardevik pls close issue once PR will be accepted.

@akshay-nm consider to create new issue for such task. It will be CLI development.

@DemaPy
Copy link

DemaPy commented Dec 28, 2024

@akshay-nm Also it looks strange that utils.tsx file has been overwritten. Because default behavior for add command is: overwrite: false

image

And there is also check in file update-files.ts
image

So, please make sure to test it again and if it happend create new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants