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

@yoonhaemin-lib/use-param-state

v1.0.0

Published

state관리를 useState가 아닌 param으로 관리합니다. useState와 인터페이스가 같아 기존에 있는 state를 url로 의존성을 옮기기 쉽습니다.

Downloads

75

Readme

useParamState

state관리를 useState가 아닌 param으로 관리합니다. useState와 인터페이스가 같아 기존에 있는 state를 url로 의존성을 옮기기 쉽습니다.

예시 코드

import React from 'react';
import useParamState from './useParamState';

const ExampleComponent: React.FC = () => {
  // 'page'와 'filter'라는 두 개의 쿼리 파라미터를 관리하는 상태로 설정
  const [searchParams, setSearchParams] = useParamState<{ page: string | undefined; filter: string | undefined }>({
    page: '1',
    filter: undefined,
  });

  const handleNextPage = () => {
    setSearchParams((prevState) => ({
      ...prevState,
      page: (Number(prevState.page) + 1).toString(),
    }));
  };

  const handleFilterChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    setSearchParams((prevState) => ({
      ...prevState,
      filter: event.target.value,
    }));
  };

  return (
    <div>
      <h2>현재 페이지: {searchParams.page}</h2>
      <h2>현재 필터: {searchParams.filter ?? '없음'}</h2>

      <button onClick={handleNextPage}>다음 페이지로 이동</button>

      <input type="text" placeholder="필터 입력" value={searchParams.filter ?? ''} onChange={handleFilterChange} />
    </div>
  );
};

export default ExampleComponent;

API Reference

useParamState 매개변수

| 매개변수 | 타입 | 설명 | 필수 여부 | | ---------------- | ------------------- | ----------------------------------------------------- | --------- | | `initialValue` | `T` | 초기값 입니다. 객체 형태로 입력합니다. | X | | `options` | `NavigateOptions` | 상태 변경시 url 변경을 어떻게 할지에 대한 옵션입니다. | X |

useParamState 반환값

| 반환값 | 타입 | 설명 | | ------------------- | ----------------------- | ------------------------------------------------------------------------------------------------- | | `searchParams` | `T` | 현재 URL query parm의 상태를 나타내는 객체입니다. | | `setSearchParams` | `ParamStateSetter` | 검색 파라미터를 업데이트하는 함수입니다. 객체 또는 새로운 상태를 반환하는 함수를 인자로 받습니다. |