---
title: getStorage
nav:
  title: Tools
  path: /tools
group:
  title: Storage
toc: content
---

## getStorage

Demo:

```tsx
/**
 * title: 基础用法
 * description: 获取 storage 存储数据函数
 */

import React from 'react';
import { getStorage } from 'aim-tools';

export default () => (
  <pre>
    <code>
      getStorage('name', 'admin', false); // 从 localStorage 中获取 name
      的值，如果没有，则返回默认值 admin
      <br />
      <br />
      getStorage('name', '', true); // 从 sessionStorage 中获取 name 的值，如果没有，则返回默认值''
    </code>
  </pre>
);
```

### API

```typescript
getStorage(
  name: string,
  defaultValue: any,
  isSessionStorage: boolean
);
```

### Params

| 参数             | 说明                  | 类型    | 默认值 | 必填 |
| :--------------- | :-------------------- | :------ | :----- | :--- |
| name             | storage 中的 key      | string  | -      | 是   |
| defaultValue     | 该 key 对应的默认值   | any     | -      | 否   |
| isSessionStorage | 是否为 sessionStorage | boolean | false  | 否   |

### Returns

| 返回值 | 说明 |
| :----- | :--- |
| ----   | ---- |
