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

@vtex/admin-ui-hooks

v0.8.4

Published

admin-ui shared hooks

Downloads

6,525

Readme

@vtex/onda-hooks

Onda shared hooks

Documentation site: https://admin-ui-docs.vercel.app/guide/get-started/

NPM

Installation

React v16.8 and above is required.

yarn add @vtex/onda-hooks

Hooks

useDebounce

Keeps a debounced value.

function Input() {
  const [text, setText] = React.useState('Hello')
  const [value] = useDebounce(text, 1000)

  return (
    <div>
      <input
        defaultValue={'Hello'}
        onChange={(e) => {
          setText(e.target.value)
        }}
      />
      <p>Actual value: {text}</p>
      <p>Debounce value: {value}</p>
    </div>
  )
}

useDebouncedCallback

Besides useDebounce for values you can debounce callbacks, that is the more commonly understood kind of debouncing

function Input({ defaultValue }) {
  const [value, setValue] = React.useState(defaultValue)
  // Debounce callback
  const debounced = useDebouncedCallback(
    // function
    (value) => {
      setValue(value)
    },
    // delay in ms
    1000
  )

  // you should use `e => debounced(e.target.value)` as react works with synthetic events
  return (
    <div>
      <input
        defaultValue={defaultValue}
        onChange={(e) => debounced(e.target.value)}
      />
      <p>Debounced value: {value}</p>
    </div>
  )
}

useDebouncedState

Keeps the state of a debounced callback.

function Input() {
  const [state, setState] = useDebouncedState({
    initialState: '',
    timeoutMs: 250,
  })

  return (
    <div>
      <input
        style={{
          border: '1px solid #333',
        }}
        defaultValue="Default value"
        onChange={(e) => setState(e.target.value)}
      />
      <p>Debouced state: {state}</p>
    </div>
  )
}

You can also use produce to apply state changes.

const [double, setDouble] = useDebouncedState({
  initialState: 1,
  timeoutMs: 250,
  // the state will always be multiplied by two
  produce: (s) => s * 2,
})

setDouble(20) // the state will be 40

useDebouncedCache

Same as useDebouncedState but it keeps the state, debounced state and setState

function Input() {
  const [state, debouncedState, setState] = useDebouncedCache({
    initialState: '',
    timeoutMs: 250,
  })

  return (
    <div>
      <input
        style={{
          border: '1px solid #333',
        }}
        value={state}
        onChange={(e) => setState(e.target.value)}
      />
      <p>State: {state}</p>
      <p>Debouced state: {debouncedState}</p>
    </div>
  )
}

Like useDebouncedState, you can use produce to apply state changes.

const [double, debouncedDouble setDouble] = useDebouncedState({
  initialState: 1,
  timeoutMs: 250,
  // the state will always be multiplied by two
  produce: (s) => s * 2,
})

setDouble(20) // the state will be 40
// after 250ms, the debouncedDouble will be 40

useQueryState

Persisted keys states in query string params (URL). Use setState to update the query string params. The state will also reflect the changes. initial state will keep the value in the amount of component (page load).

useQueryState should be used inside of QueryStateProvider

function Input() {
  const [initialState, setState, state] = useQueryState({
    keys: ['search'],
  })

  return (
    <QueryStateProvider>
      <input
        defaultValue={initialSate}
        onChange={(e) => {
          setState({ serach: e.target.value })
        }}
      />
      <p>Actual value: {state.search}</p>
      <p>Initial value: {initialState.search}</p>
    </QueryStateProvider>
  )
}