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

solid-request

v1.2.0

Published

solid-js use-request hooks library

Downloads

1

Readme

Solid-request

With a strong ability to manage network requests, Hook has a flying experience

Usage

Install

npm i solid-request

Import

import useRequest from "solid-request"

useRequest Through the plug-in organization code, the core code is easy to understand, and can be easily expanded to more advanced functions. Capacity is now available to include

  • Automatic/manual request
  • Support Typescript
  • Polling
  • Debounce
  • Throttle
  • Refresh on window focus
  • Error retry
  • Loading delay
  • SWR(stale-while-revalidate)
  • Caching
  • Plugins

Default request

By default, the first parameter of useRequest is an asynchronous function, which is automatically executed when the component is initialized. At the same time, it automatically manages the status of loading, data, error of the asynchronous function.

const { data, error, loading } = useRequest(service)

example

export async function getList({ id }: { id: number }): Promise<{
	id: number
	title: string
	body: string
	userId: number
}> {
	console.log(id)

	return fetch(`https://jsonplaceholder.typicode.com/posts/${id}`).then(
		(response) => response.json()
	)
}

function App() {
	const [count, setCount] = createSignal(1)
  
	const { data, loading } = useRequest(() => getList({ id: count() }), {
		manual: false,
		ready: true,
		refreshDeps: true,
		loadingDelay: 300,
	})

	return (
		<div>
			<button type="button" onClick={increment}>
				{count()}
			</button>
			<div>{loading() ? 'loading...' : JSON.stringify(data())}</div>
		</div>
	)
}

The document is under development, for more APIs, please see the vue version of useRequest

Result

| Property | Description | Type | | ------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | | data | Data returned by service | Accessor<TData \| undefined> | | error | Exception thrown by service |Accessor\|undefined | | loading | Is the service being executed |Accessor | | params | An array of parameters for the service being executed. For example, you triggeredrun(1, 2, 3), then params is equal to [1, 2, 3]|Accessor<TParams | []> | | run | <ul><li> Manually trigger the execution of the service, and the parameters will be passed to the service</li><li>Automatic handling of exceptions, feedback throughonError</li></ul> | (...params: TParams) => void | | runAsync | The usage is the same asrun, but it returns a Promise, so you need to handle the exception yourself. | (...params: TParams) => Promise | | refresh | Use the last params, callrunagain |() => void | | refreshAsync | Use the last params, callrunAsyncagain |() => Promise | | mutate | Mutatedatadirectly |(data?: TData / ((oldData?: TData) => (TData / undefined))) => void| | cancel | Ignore the current promise response |() => void` |

Options

| Property | Description | Type | Default | | ------------- | ------------------------------------------------------------ | ---------------------------------------------------- | ------- | | initialData | Init data | TData | undefined | | | manual | The default is false. That is, the service is automatically executed during initialization.If set to true, you need to manually call run or runAsync to trigger execution. | boolean | false | | defaultParams | The parameters passed to the service at the first default execution | TParams | - | | formatResult | Format the request results, which recommend to use useFormatResult | (response: TData) => any | - | | onBefore | Triggered before service execution | (params: TParams) => void | - | | onSuccess | Triggered when service resolve | (data: TData, params: TParams) => void | - | | onError | Triggered when service reject | (e: Error, params: TParams) => void | - | | onFinally | Triggered when service execution is complete | (params: TParams, data?: TData, e?: Error) => void | - |