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

@confidential-nt/localstorage-query

v0.2.1

Published

LocalStorage를 좀 더 간편하게 사용하기 위해 만든 라이브러리입니다.

Downloads

427

Readme

LocalStorage Query

설명

로컬 스토리지를 좀 더 간편하게 사용하기 위해 만든 라이브러리입니다.

기능

  • 로컬 스토리지에서 값 조회
  • 로컬 스토리지에서 값 변경 (수정, 삭제)
  • 로컬 스토리지에 key - value를 즉시 생성 및 초기화 (단, 로컬 스토리지에 key에 해당하는 값이 없는 경우)

사용법

설치

npm install @confidential-nt/localstorage-query

예제

Javascript

const key = 'todo';

function App() {
  const { data, mutate, remove } = useLocalstorageQuery(key, [
    {
      title: '밥먹기',
      completed: false,
      id: '1',
    },
  ]); // key에 해당하는 값이 로컬 스토리지에 없을 경우, 주어진 initial value로 즉시 초기화됩니다. 그렇지 않은 경우 무시됩니다.

  // ... do something
}

Typescript

type TodoItem = {
  title: string;
  completed: boolean;
  id: string;
};

const key = 'todo';

export default function App() {
  const { data, mutate, remove } = useLocalstorageQuery<TodoItem[]>(key, [
    {
      title: '밥먹기',
      completed: false,
      id: "1",
    },
  ]); // key에 해당하는 값이 로컬 스토리지에 없을 경우, 주어진 initial value로 즉시 초기화됩니다. 그렇지 않은 경우 무시됩니다.

  // ... do something
}

더 자세한 예제를 보려면 아래 링크를 클릭하세요.

투두리스트 예시코드 투두리스트 예시사이트

참조

구문

useLocalstorageQuery(key);
useLocalstorageQuery(key, initialValue);

매개변수

  • key: 로컬스토리지에서 key로 쓸 값을 지정합니다.
  • initialValue(optional): 위에서 지정한 key에 대해 초기값으로 사용하고 싶은 value를 지정합니다. key에 해당하는 값이 로컬 스토리지에 없을 경우 주어진 initial value로 즉시 초기화됩니다. 그렇지 않은 경우 무시됩니다.

반환 값

다음 객체를 반환합니다.

const { data, mutate, remove } = useLocalstorageQuery(key);
  • data: 로컬 스토리지에 저장했던 값을 반환합니다.
  • mutate(newData): 로컬 스토리지에 저장한 값을 변경하는 함수입니다. 매개변수로 변경된 데이터를 넣어줍니다. 불변성을 유지해야합니다.
  • remove(): 로컬 스토리지에 저장했던 key에 해당하는 값을 전부 지우는 함수입니다.