import { Meta } from '@storybook/addon-docs';

<Meta title='Components/CognitoAuth/Sigv4Client/Docs' />

# useSigv4Client

A React hook returning an instance of Sigv4Client to be used to run fetch call with AWS signed API requests.

## Usage 

useSigv4Client should be used within **CognitoAuth** context. 

**identityPoolId** and **region** should be provided as props of CognitoAuth component. 

```jsx
import useSigv4Client from '@aws-northstar/ui/components/CognitoAuth/hooks/useSigv4Client';

...
    // Get Sigv4Client fetch callback
    const client = useSigv4Client();
    const [response, setResponse] = useState();
    const [error, setError] = useState<Error>();
    
    const handleFetch = useCallback(async () => {
        try {
            const response = await client(<url>, <RequestInit>);
            setResponse(await response.json());
        } catch (err) {
            setError(err);
        }
    }, [client, url]);
...

```


