npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jk-core/hooks

v0.0.8

Published

hooks for jk

Downloads

378

Readme

@jk-core/hooks

jk-core 프로젝트를 위한 React 커스텀 훅 모음입니다.

설치

npm install @jk-core/hooks // npm 사용 가능
yarn add @jk-core/hooks // npm 대신 yarn 사용 가능
pnpm add @jk-core/hooks // npm 대신 pnpm 사용 가능

useIntersectionObserver

무한 스크롤을 구현하기 위한 Intersection Observer API를 사용하는 훅입니다.

Props

  • callback: () => void - 교차점 관찰 시 실행될 함수
  • margin: string (선택적, 기본값: '5px') - 관찰 영역의 마진

Return

  • observerRef: RefObject - 관찰 대상 요소에 연결할 ref
  • parentRef: RefObject - 부모 요소에 연결할 ref

사용법

import { useIntersectionObserver } from '@jk-core/hooks';
const MyComponent = () => {
const loadMoreItems = () => {
// 추가 아이템을 로드하는 로직
};
const { observerRef, parentRef } = useIntersectionObserver(loadMoreItems);
return (
<div ref={parentRef}>
{/ 아이템 목록 /}
<div ref={observerRef}>로딩 중...</div>
</div>
);
};

useInterectOutside

클릭한 위치가 요소 바깥인지 확인하는 훅입니다.

Props

  • targetRef: RefObject - 대상 요소의 ref
  • eventList: string[] - 감지할 이벤트 목록
  • handler: () => void - 요소 외부 클릭 시 실행될 함수

사용법

import { useInterectOutside } from '@jk-core/hooks';
const MyComponent = () => {
const handleClickOutside = () => {
// 클릭한 위치가 요소 바깥일 때 실행되는 로직
};
const { ref } = useInterectOutside(handleClickOutside);
return <div ref={ref}>Click outside to trigger</div>;
};

useMediaQuery

미디어 쿼리를 사용하여 화면 크기를 확인하는 훅입니다.

Props

  • width: number - 기준이 되는 화면 너비 (픽셀)

Return

  • boolean: 현재 화면 크기가 지정된 너비보다 작은지 여부

사용법

import { useMediaQuery } from '@jk-core/hooks';
const MyComponent = () => {
const isMobile = useMediaQuery(768);
return <div>{isMobile ? 'Mobile' : 'Desktop'}</div>;
};

useHistory

브라우저의 history API를 사용하여 페이지 내비게이션을 관리하는 훅입니다.

Return

  • push: (path: string) => void - 현재 path에 가상의 path를 추가하는 함수
  • back: () => void - 이전 페이지로 이동하는 함수

사용법

import { useHistory } from '@jk-core/hooks';
const MyComponent = () => {
const { push, back } = useHistory();
return (
<div>
<button onClick={() => push('/page1')}>Page 1</button>
<button onClick={() => back()}>Back</button>
</div>
);
};

useHistoryEvent

브라우저의 history 이벤트를 관리하는 훅입니다.

Props

  • listener: (update: Update) => void - history 이벤트 처리 함수

Update 객체

  • action: 'POP' | 'PUSH' | 'REPLACE' - 수행된 history 액션
  • location: Location - 현재 location 객체

사용법

import { useHistoryEvent } from '@jk-core/hooks';
const MyComponent = () => {

// history 이벤트 처리 로직
const handleHistoryEvent = ((update: Update) =>{
  if(event.action === 'PUSH') {
     // history push 이벤트 처리 로직
  }
  if(event.action === 'REPLACE') {
     // history replace 이벤트 처리 로직
  }
  if(event.action === 'POP') {
     // history pop 이벤트 처리 로직
  }
};

useHistoryEvent(handleHistoryEvent);
return <div>History Event Listener</div>;
};