New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-async-render-props

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-async-render-props

It is a component to build children by resolving a promise with Render Props pattern.

latest
Source
npmnpm
Version
1.2.0
Version published
Weekly downloads
5
400%
Maintainers
1
Weekly downloads
 
Created
Source

React Async Render Props

It is a component to build children by resolving a promise with Render Props pattern.

Usage

import AsyncRender, { type ActionType, useActionHandler } from 'react-async-render-props'

function Foo() {
    const actionRef = useActionHandler()
    return (
        <>
            <Button onClick={() => {
                actionRef.current!.runAsync()
            }}>fetch</Button>
            <AsyncRender id='fooId' actionRef={actionRef} request={() => {
                return new Promise<SelectOption[]>(resolve => {
                    setTimeout(() => {
                        resolve([
                            {
                                label: Math.random().toString(36),
                                value: 'xxx'
                            },
                        ])
                    }, 500);
                })
            }}>
                {
                    ({ loading, data, runAsync }) => {
                        return (
                            <Spin spinning={loading}>
                                <Button onClick={() => {
                                    runAsync()
                                }}>fetch</Button>
                                <ProFormSelect options={data}/>
                            </Spin>
                        )
                    }
                }
            </AsyncRender>
        </>
    )
}

export default function App() {
    return (
        <div>
            <div onClick={() => {
                AsyncRender.getHandler('fooId').runAsync()
            }}>clickme</div>
            <Foo />
        </div>
    )
}

API

NameTypeDescription
request(...params: P) => Promise\<T\>Required, A function returning a promise (it will be called when the component is mounted)
children(result: ReturnType\<typeof useRequest\<T, P\>\>) => React.ReactElementRequired, A render props function
actionRefReact.MutableRefObject\<ActionType\<T, P\>\>get useRequest result
options-useRequest options
idstringmark instance
forceUpdatebooleanforce update when fired
AsyncRender.getHandler(id: string) => ActionTypeget action handler
type ActionType<T = any, P extends any[] = any> = ReturnType<typeof useRequest<T, P>> & {
  setParam: (partialParam: any, index?: number) => void
}

License

MIT

Keywords

react async render props

FAQs

Package last updated on 20 Apr 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