Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

create-react-suspense

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-react-suspense

`create-react-suspense` is a utility function that helps you handle promises in a way that integrates with React's Suspense mechanism. It allows you to create a function that can be called to handle a promise and return its result or error.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

create-react-suspense

create-react-suspense is a utility function that helps you handle promises in a way that integrates with React's Suspense mechanism. It allows you to create a function that can be called to handle a promise and return its result or error.

Installation

npm install create-react-suspense

Usage

Importing the Function

import createReactSuspense from 'create-react-suspense'

Example

Using with an Initial Promise
const useSuspense1 = createReactSuspense(
  fetch('https://jsonplaceholder.typicode.com/todos/1')
)

function DataLoadComponent1() {
  const [error, data] = useSuspense1()

  if (error) {
    return <div>Error: {error}</div>
  }

  return <div>Data: {data}</div>
}
Using without an Initial Promise
const useSuspense2 = createReactSuspense()

function DataLoadComponent2() {
  const [error, data] = useSuspense2(
    fetch('https://jsonplaceholder.typicode.com/todos/1')
  )

  if (error) {
    return <div>Error: {error}</div>
  }

  return <div>Data: {data}</div>
}

API

createReactSuspense<T>(promise?: Promise<T>): useSuspense

useSuspense<T>(promise?: Promise<T>): [error, data]

FAQs

Package last updated on 21 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc