Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Storing a boolean in user preferences

default discord avatar
tinouti2 years ago
1

Has anyone ever done this successfully?



I'm having the following issue when I try to do it:



setPreference('key', true);
const preference = await getPreference('key');
console.log(preference, typeof preference); // true, boolean

setPreference('key', false);
const preference = await getPreference('key');
console.log(preference, typeof preference); // {value: false}, object


Payload returns an object with a

value

property set to false instead of returning

false

. 🤔



I worked around it doing this:


const preference = await getPreference('key');
setPreference(preference && typeof preference === "boolean");

But I'm wondering if this behavior is a bug or if it's working as intended. 🤔

    Star on GitHub

    Star

    Chat on Discord

    Discord

    online

    Can't find what you're looking for?

    Get dedicated engineering support directly from the Payload team.