---
schema_version: "1"
id: 1896f7e3f8b6d7ed3482add4a2e8fa1a6e89f45842112d113859aa60ec40928d
title: setAttribute
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud-mobilepush/engagement_sdk/references/react/react_setAttribute.md
canonical_url: https://developer.salesforce.com/docs/marketing/mobile-unified-sdk/references/engagement-mobile-sdk-reference/react_setAttribute.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 82d59c99f563888ee6fd746bcd232b751f8dafdf2f15b07849a43a7ea9fdf0f5
products:
  - Salesforce Engagement SDK
---
# setAttribute

Sets the value of an attribute in the registration.

## Syntax

```javascript
MCReactModule.setAttribute(key, value);
```

## Parameters

| Parameter | Type     | Description                                                     |
| --------- | -------- | --------------------------------------------------------------- |
| `key`     | `string` | The name of the attribute to be set in the registration.        |
| `value`   | `string` | The value of the `key` attribute to be set in the registration. |

## Returns

- `void` - No return value.

## Example

```javascript
import { MCReactModule } from "react-native-marketingcloudsdk";

const setUserAttribute = () => {
  try {
    MCReactModule.setAttribute("userType", "premium");
    MCReactModule.setAttribute("lastLogin", new Date().toISOString());
    console.log("Attributes set successfully");
  } catch (error) {
    console.error("Error setting attribute:", error);
  }
};
```

## See Also

- [getAttributes() Method](https://developer.salesforce.com/docs/marketing/mobile-unified-sdk/references/engagement-mobile-sdk-reference/react_getAttributes.md)
- [clearAttribute() Method](https://developer.salesforce.com/docs/marketing/mobile-unified-sdk/references/engagement-mobile-sdk-reference/react_clearAttribute.md)
- [Android SDK Reference](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/SFMCSdk/8.0/-s-f-m-c%20-s-d-k/com.salesforce.marketingcloud.sfmcsdk.components.identity/-identity/set-profile-attribute.html)
- _SDK Reference for iOS_: [Identity Class](https://developer.salesforce.com/docs/marketing/mobile-unified-sdk/references/ios-sdk-v11/sfmc-sdk/classes/identity.md)
