1 year ago

#124425

test-img

Evan Winter

How do I retrieve custom properties on a LaunchDarkly user?

I'm trying to add an attribute to a LaunchDarkly user, and retrieve it on subsequent reloads.

Here's a simplified example:

import { withLDProvider } from 'launchdarkly-react-client-sdk';
export default withLDProvider({
  clientSideID: 'your-client-side-id',
  user: {
    "key": "abc",
  },
  options: { /* ... */ }
})(YourApp);

const YourApp = () => {
  const client = useLDClient();
  useEffect(() => {
    if (client) {
      const user = client.getUser();
      
      // Expectation: logs "{ key: 'abc' } on first load,
      // and "{ key: 'abc', firstName: 'Evan' }" on subsequent reloads
      console.log('Received', user);

      const updatedUser = { ...user, firstName: 'Evan' };
      client.identify(updatedUser);
    }
  }

  ...
}

What I'm seeing is that after reloading the page, the 'firstName' attribute is not being retrieved.

Expected:

  • First load: Received { key: 'abc' }
  • Second load: Receieved { key: 'abc', firstName: 'Evan' }

Reality:

  • First load: Received { key: 'abc' }
  • Second load: Received { key: 'abc' }

Am I misunderstanding what getUser() is supposed to do?

My understanding is that calling identify() should update the user profile. I would think that on subsequent getUser() calls with the same key, I should get back the firstName that is added when calling identify() but that's not what I'm seeing.

I've read through all the docs and I can't tell if this is expected behavior, or if I'm doing something wrong.

I'm using the React Client SDK ("launchdarkly-react-client-sdk": "^2.22.2")

javascript

reactjs

launchdarkly

0 Answers

Your Answer

Accepted video resources