Menu

A dismissed banner that comes back after a week: two localStorage keys, and the rule for what a missing timestamp means
📰

A dismissed banner that comes back after a week: two localStorage keys, and the rule for what a missing timestamp means

DEV Community: react·Daniel Pertu·about 17 hours ago
#8Xu0DxDs
#devtoreact#devto#dev#state#time
Long article (782 words) — no AI summary yet.
Reading 0:00
15s threshold

We have a temporary programme that invites signed-in users to take a set of free tests on a sister product. It needed a prompt. The first version was the usual one: a card at the foot of the dashboard, a close button, and once you closed it, never again.

That is the wrong behaviour for a programme with a short life and a goal of getting people to take part. A closed card should be a "not now". So the next commit turned it into a slim banner near the top and changed the dismissal to "hide for a week, then return". Opening the tests still hides the prompts for good.

The interesting part is how little it needed, and one rule in the middle that is easy to get wrong.

The whole state is two strings

No database column. The feature is explicitly temporary and its README ends with a removal checklist that says nothing was added to the database, so there is nothing to migrate when it goes.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.