Actually, no… it’s the other way around…
Data for a Thing is only retrieved from the database when you reference a field from that thing - and that includes the unique ID field.
Take the following example DB:
Book
Name
Other data 1
Other data 2
Other data 3
etc.
Unique ID
User
Name
Favourite Book (of type Book)
Unique ID
When a User loads a page, all of their User data is loaded, e.g.
Name: Dave
Favourite Book: 019283746786x8373984383927482746
Unique ID: 02823827382738x91738297169291100
Referenced things are just stored (and loaded) as a string (unique ID) until you actually make a reference to a field from that thing (and that includes the unique ID itself), at which point the full data of the thing will be loaded.
No data at all will be retrieved from the Book database if you don’t refer to any fields from it.
So, if you have a custom state of type ‘Book’ on your page, and you set it to the Current User's Favourite Book
, all that happens is that the lookup reference to the book is set into that state - no more data is loaded to the page.
If, however, you had a custom state of type ‘Text’, and you set that to the Current User's Favourite Book's Name
, in order to access the book’s Name, the entire data of the book has to be loaded to the page.
And the same applies to setting the text custom state’s value to the Current User's Favourite Book's Unique ID
(although you might well think that wouldn’t be the case - since the unique ID is already on the page in the User’s Favourite Book field - but it is). Simple to test this with your browser dev tools.
So, to summarise:
i.e. it’s more light-weight to set the custom state to the Thing… not the Thing’s Unique ID
So, as already pointed out in this thread, the correct way to do this is to set the custom state to the Thing itself.
Obviously, if the thing (or things) have already been loaded to the page (and in many, if not most cases, including your specific example, they will have been) then it makes no difference in terms of the actual data/memory efficiency etc. but still… the correct way is to use Things, not fields from Things (including unique IDs).