---
title: Interface: UseUser
slug: chord-ui/interface-useuser
docTags: 
createdAt: 2023-11-06T15:03:31.906Z
---

[react-autonomy](docId\:zoZ6W56ubpPACr0PO0GLS).UseUser

UseUser contains the data and methods returned by the [useUser](docId\:bctsQ3gxNghVdBgTam2hY) hook.

## Properties

### loadUser

• **loadUser**: () => `Promise`\<`void`>

### Type declaration

▸ (): `Promise`\<`void`>

The `loadUser` function loads information about the current order's
associated user from the Chord API.



```javascript
import { useUser } from '@chordcommerce/react-autonomy'

export default () => {
  const { user, loadUser } = useUser()

  useEffect(() => {
    loadUser()
  }, [])

  return <p>Welcome, {user.data.email}!</p>
}
```

### Returns

`Promise`\<`void`>

A Promise that resolves when the `user` object has been added to
Redux.

### Defined in

[packages/react-autonomy/src/hooks/use-user.ts:125](https://github.com/chordcommerce/chord-ui/blob/2b105e1/packages/react-autonomy/src/hooks/use-user.ts#L125)

***

### loadUserAddressBook

• **loadUserAddressBook**: () => `Promise`\<[`AddressBook`](docId\:VwvT8IOJa7OYm5BQ-qVv4)>

### Type declaration

▸ (): `Promise`\<[`AddressBook`](docId\:VwvT8IOJa7OYm5BQ-qVv4)>

The `loadUserAddressBook` function loads the current user's stored addresses. A user must be
already logged in for this method to work properly.



```javascript
import { useUser } from '@chordcommerce/react-autonomy'

export default () => {
  const { user, loadUserAddressBook } = useUser()

  useEffect(() => {
    loadUserAddressBook()
  }, [])

  if (!user.addressBook) return null

  return (
    <ul>
      {user.addressBook.map(address => (
        <li>{address.name} - {address.address1} {address.city}, {address.stateText}</li>
      )}
    </ul>
  )
}
```

### Returns

`Promise`\<[`AddressBook`](docId\:VwvT8IOJa7OYm5BQ-qVv4)>

A Promise that resolves when the array of addresses, `addressBook` has been added to
Redux.

### Defined in

[packages/react-autonomy/src/hooks/use-user.ts:243](https://github.com/chordcommerce/chord-ui/blob/2b105e1/packages/react-autonomy/src/hooks/use-user.ts#L243)

***

### loadUserReferralIdentifier

• **loadUserReferralIdentifier**: (`options`: [`LoadUserReferralIdentifier`](docId\:mUnNRX729WZwkx8i39MXN)) => `Promise`\<[`ReferralIdentifier`](docId\:ul_gRV5q_Ut1V77RAVKRo)>

### Type declaration

▸ (`options`): `Promise`\<[`ReferralIdentifier`](docId\:ul_gRV5q_Ut1V77RAVKRo)>

The `loadUserReferralIdentifier` function loads the referral identifier
information for a user with the given email address from the Chord API.



```javascript
import { useUser } from '@chordcommerce/react-autonomy'

export default () => {
  const { user, loadUserReferralIdentifier } = useUser()
  const referralPurl = user.referralIdentifier && user.referralIdentifier.purl

  useEffect(() => {
    loadUserReferralIdentifier()
  }, [])

  return (
    <p>Refer your friends with your personal referral link: {referralPurl}</p>
  )
}
```

### Parameters

| Name      | Type                                                         |
| --------- | ------------------------------------------------------------ |
| `options` | [`LoadUserReferralIdentifier`](docId\:mUnNRX729WZwkx8i39MXN) |

### Returns

`Promise`\<[`ReferralIdentifier`](docId\:ul_gRV5q_Ut1V77RAVKRo)>

A Promise that resolves when the `referralIdentifier` object has
been added to the `user` object in Redux.

### Defined in

[packages/react-autonomy/src/hooks/use-user.ts:152](https://github.com/chordcommerce/chord-ui/blob/2b105e1/packages/react-autonomy/src/hooks/use-user.ts#L152)

***

### loadUserStoreCreditEvents

• **loadUserStoreCreditEvents**: () => `Promise`\<[`StoreCreditEvents`](docId\:BDqyxXVrLbiGB2p-vJ-yG)>

### Type declaration

▸ (): `Promise`\<[`StoreCreditEvents`](docId\:BDqyxXVrLbiGB2p-vJ-yG)>

The `loadUserStoreCreditEvents` function loads information about the current user's
store credit history. A user must be already logged in for this method to work properly.



```javascript
import { useUser } from '@chordcommerce/react-autonomy'

export default () => {
  const { user, loadUserStoreCreditEvents } = useUser()

  useEffect(() => {
    loadUserStoreCreditEvents()
  }, [])

  if (!user.storeCreditEvents) return null

  return (
    <ul>
      {user.storeCreditEvents.map(event => (
        <li>{event.displayEventDate} - {event.displayAction} {event.displayAmount}
        ({event.displayRemainingAmount} remaining)</li>
      )}
    </ul>
  )
}
```

### Returns

`Promise`\<[`StoreCreditEvents`](docId\:BDqyxXVrLbiGB2p-vJ-yG)>

A Promise that resolves when the array of `storeCreditEvents` has been added to
Redux.

### Defined in

[packages/react-autonomy/src/hooks/use-user.ts:210](https://github.com/chordcommerce/chord-ui/blob/2b105e1/packages/react-autonomy/src/hooks/use-user.ts#L210)

***

### modifyUser

• **modifyUser**: (`options`: [`ModifyUser`](docId:-yhHr4FZjwtqORcU_3Ssm)) => `Promise`\<`void`>

### Type declaration

▸ (`options`): `Promise`\<`void`>

The `modifyUser` function is used to update the user's profile information.



```javascript
import { useUser } from '@chordcommerce/react-autonomy'

export const AccountPage => {
  const { modifyUser } = useUser()
  const onSubmit = ({ email }) => {
    modifyUser({ email })
  }

  // return profile edit form
}
```

### Parameters

| Name      | Type                                        |
| --------- | ------------------------------------------- |
| `options` | [`ModifyUser`](docId:-yhHr4FZjwtqORcU_3Ssm) |

### Returns

`Promise`\<`void`>

A Promise that resolves when the `user` object has been updated in
Redux.

### Defined in

[packages/react-autonomy/src/hooks/use-user.ts:176](https://github.com/chordcommerce/chord-ui/blob/2b105e1/packages/react-autonomy/src/hooks/use-user.ts#L176)

***

### modifyUserAddressBook

• **modifyUserAddressBook**: (`address`: `UpdateAddressInput`) => `Promise`\<[`AddressBook`](docId\:VwvT8IOJa7OYm5BQ-qVv4)>

### Type declaration

▸ (`address`): `Promise`\<[`AddressBook`](docId\:VwvT8IOJa7OYm5BQ-qVv4)>

The `modifyUserAddressBook` function updates an address the current user's stored addresses.
A user must be already logged in for this method to work properly.



```javascript
import { useUser } from '@chordcommerce/react-autonomy'

export default () => {
  const { user, loadUserAddressBook, modifyUserAddressBook } = useUser()

  useEffect(() => {
    loadUserAddressBook()
  }, [])

  const setAddressToDefault = (addressId) => {
    const addressToUpdate = { ...user.addressBook.find(a => a.id === addressId) }

    delete addressToUpdate.country
    delete addressToUpdate.state
    addressToUpdate.default = true

    modifyUserAddressBook(addressToUpdate)
  }

  if (!user.addressBook) return null

  return (
    <ul>
      {user.addressBook.map(address => (
        <li onClick={() => setAddressToDefault(address.id)}>
          {address.name} - {address.address1} {address.city}, {address.stateText}
        </li>
      )}
    </ul>
  )
}
```

### Parameters

| Name      | Type                 |
| --------- | -------------------- |
| `address` | `UpdateAddressInput` |

### Returns

`Promise`\<[`AddressBook`](docId\:VwvT8IOJa7OYm5BQ-qVv4)>

A Promise that resolves when the array of addresses, `addressBook` has been updated
in Redux.

### Defined in

[packages/react-autonomy/src/hooks/use-user.ts:288](https://github.com/chordcommerce/chord-ui/blob/2b105e1/packages/react-autonomy/src/hooks/use-user.ts#L288)

***

### removeFromUserAddressBook

• **removeFromUserAddressBook**: (`addressId`: `number`) => `Promise`\<`void`>

### Type declaration

▸ (`addressId`): `Promise`\<`void`>

The `removeFromUserAddressBook` function removes an address the current user's stored addresses.
A user must be already logged in for this method to work properly.



```javascript
import { useUser } from '@chordcommerce/react-autonomy'

export default () => {
  const { user, loadUserAddressBook, removeFromUserAddressBook } = useUser()

  useEffect(() => {
    loadUserAddressBook()
  }, [])

  const removeAddress = (addressId) => {
    removeFromUserAddressBook(addressId)
  }

  if (!user.addressBook) return null

  return (
    <ul>
      {user.addressBook.map(address => (
        <li onClick={() => removeAddress(address.id)}>
          {address.name} - {address.address1} {address.city}, {address.stateText}
        </li>
      )}
    </ul>
  )
}
```

### Parameters

| Name        | Type     |
| ----------- | -------- |
| `addressId` | `number` |

### Returns

`Promise`\<`void`>

A Promise that resolves when the array of addresses, `addressBook` has been updated
in Redux to reflect the removal of the address id passed to this function.

### Defined in

[packages/react-autonomy/src/hooks/use-user.ts:327](https://github.com/chordcommerce/chord-ui/blob/2b105e1/packages/react-autonomy/src/hooks/use-user.ts#L327)

***

### user

• **user**: `Object`

Chord's user state.

The `data` property contains the user's information. It will be an empty
object if the user is not logged in, which allows for top level optional
chaining.



```javascript
import { useUser } from '@chordcommerce/react-autonomy'

function Greeting() {
  const { user } = useUser()

  return <h1>Hello{user.data?.name ? `, ${user.data.name}` : ''}!</h1>
}
```

### Type declaration

| Name                 | Type                                                                   |
| -------------------- | ---------------------------------------------------------------------- |
| `addressBook`        | [`AddressBook`](docId\:VwvT8IOJa7OYm5BQ-qVv4)                          |
| `data`               | [`User`](docId\:zayf-YT0nLpyDpHK2V988) \| `Record`\<`string`, `never`> |
| `referralIdentifier` | `string`                                                               |
| `storeCreditEvents`  | [`StoreCreditEvents`](docId\:BDqyxXVrLbiGB2p-vJ-yG)                    |

### Defined in

[packages/react-autonomy/src/hooks/use-user.ts:101](https://github.com/chordcommerce/chord-ui/blob/2b105e1/packages/react-autonomy/src/hooks/use-user.ts#L101)
