1.2.0 • Published 3 years ago

react-fetch-it-hook v1.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

#REACT FETCH IT HOOK

yarn add react-fetch-it-hook

##getting started

add provider

ReactDOM.render(
    <React.StrictMode>
        <FetchProvider value={{basePath: 'http://demo7542668.mockable.io', logLevel: 'INFO'}}>
            <App/>
        </FetchProvider>
    </React.StrictMode>,
    document.getElementById('root')
)

fetch example

interface IBaseResponse {
    body: unknown
}

interface IHelloResponse extends IBaseResponse {
    body: {
        messagge: string
    }
}

interface IHelloRequest {
    user: string
}

export const DumpFetchComponent: React.FC = props => {

    // can rename the response with comma
    const {response: helloResponse, error, loading, call} = useFetch<IHelloResponse, IHelloRequest>({
        url: '/{test}',
        method: HttpMethod.POST
    })

    useEffect(() => {
        setTimeout(() => {
            call({user: '1'}, {test: 'hello'}, {last: 10})
        }, 1000)
    }, [])
    useEffect(() => {
        console.info('final error ', error)

    }, [error])

    useEffect(() => {
        console.info('final response', helloResponse)
    }, [helloResponse])

    useEffect(() => {
        console.info('loading ', loading ? 'yes' : 'no')
    }, [loading])

    return <div> RESPONSE {helloResponse && JSON.stringify(helloResponse)}</div>
}

issues

  • works just debug log
1.2.0

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.0.2

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.0

3 years ago