> Documentation index: https://www.gooddata.ai/docs/gooddata-ui/llms.txt lists every page of these docs as Markdown.

# useWorkspace()

- Package: [@gooddata/sdk-ui](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui/index.md)
- Kind: function
- Source: https://github.com/gooddata/gooddata-ui-sdk/blob/rel/11.64/libs/sdk-ui/src/base/react/WorkspaceContext.tsx
- Guides: [useWorkspace](https://www.gooddata.ai/docs/gooddata-ui/latest/integrations/hooks/use-workspace/index.md)

Hook to get workspace instance provided to [WorkspaceProvider()](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui/sdk-ui.workspaceprovider/index.md).

**Signature:**

```typescript
useWorkspace: (workspace?: string) => string | undefined
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| workspace | string | _(Optional)_ workspace to use instead of context value. If undefined, the context value is used. |

**Returns:**

string &#124; undefined

## Remarks

You can set a workspace override that will be returned if defined. This makes the usage more ergonomic (see the following example).

Note: For a better TypeScript experience without the hassle of undefined values, you can use the [useWorkspaceStrict()](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui/sdk-ui.useworkspacestrict/index.md) hook.

## Example

```tsx
// instead of
const fromContext = useWorkspace();
const effectiveWorkspace = fromArguments ?? fromContext.
// you can write
const workspace = useWorkspace(fromArguments);
```
