Skip to content
← Optimistic State
Edit Optimistic State
Name
Also known as (comma separated)
Brief definition
State updated before server confirmation.
Notes
Tier
Core
Useful
Reference
Deleted
Controls schema (JSON array)
[ { "id": "itemLabel", "type": "text", "label": "Item", "default": "Post" }, { "id": "stage", "type": "select", "label": "Stage", "default": "optimistic", "options": [ "optimistic", "confirmed", "rolled-back" ] }, { "id": "accent", "type": "color", "label": "Accent colour", "default": "#F5C2E0", "presets": [ "#F5C2E0", "#A8E6C1", "#BFD9F2", "#D9C8F0", "#E8A020", "#241430" ] }, { "id": "baseLikes", "type": "number", "label": "Likes before click", "default": 12, "min": 0, "max": 999, "step": 1 } ]
Templates (JSON object keyed by format)
{ "html": "<div class=\"opt opt--{{stage}}\" role=\"status\">\n <p class=\"opt__label\">{{itemLabel}}</p>\n <div class=\"opt__like\" style=\"--a:{{accent}};\">♥ <span class=\"opt__count opt__count--optimistic\">{{baseLikes}} + 1</span><span class=\"opt__count opt__count--confirmed\">{{baseLikes}} + 1</span><span class=\"opt__count opt__count--rolled-back\">{{baseLikes}}</span></div>\n <p class=\"opt__note opt__note--optimistic\">UI updated instantly, before the server replied.</p>\n <p class=\"opt__note opt__note--confirmed\">Server confirmed — optimistic value was correct.</p>\n <p class=\"opt__note opt__note--rolled-back\">Server rejected the like — UI rolled back to the real count.</p>\n</div>\n<style>\n.opt { font: 13px/1.5 system-ui, sans-serif; color: #241430; background: #FAF7F2; padding: 18px; border-radius: 12px; width: 300px; box-sizing: border-box; }\n.opt__label { margin: 0 0 10px; font-weight: 700; }\n.opt__like { padding: 12px; border-radius: 8px; background: #24143010; text-align: center; font-size: 20px; font-weight: 800; margin-bottom: 10px; }\n.opt__count { display: none; }\n.opt--optimistic .opt__count--optimistic, .opt--confirmed .opt__count--confirmed, .opt--rolled-back .opt__count--rolled-back { display: inline; }\n.opt--optimistic .opt__like, .opt--confirmed .opt__like { color: var(--a); }\n.opt__note { display: none; margin: 0; font-size: 11px; color: #24143099; }\n.opt--optimistic .opt__note--optimistic, .opt--confirmed .opt__note--confirmed, .opt--rolled-back .opt__note--rolled-back { display: block; }\n</style>", "tailwind": "<div class=\"opttw opttw--{{stage}} font-sans text-[#241430] bg-[#FAF7F2] p-4.5 rounded-xl w-[300px] box-border\" role=\"status\">\n <p class=\"m-0 mb-2.5 font-bold\">{{itemLabel}}</p>\n <div class=\"opttw__like p-3 rounded-lg bg-[#24143010] text-center text-xl font-extrabold mb-2.5\" style=\"--a:{{accent}};\">♥ <span class=\"opttw__count opttw__count--optimistic hidden\">{{baseLikes}} + 1</span><span class=\"opttw__count opttw__count--confirmed hidden\">{{baseLikes}} + 1</span><span class=\"opttw__count opttw__count--rolled-back hidden\">{{baseLikes}}</span></div>\n <p class=\"opttw__note opttw__note--optimistic hidden m-0 text-[11px] text-[#24143099]\">UI updated instantly, before the server replied.</p>\n <p class=\"opttw__note opttw__note--confirmed hidden m-0 text-[11px] text-[#24143099]\">Server confirmed — optimistic value was correct.</p>\n <p class=\"opttw__note opttw__note--rolled-back hidden m-0 text-[11px] text-[#24143099]\">Server rejected the like — UI rolled back to the real count.</p>\n</div>\n<style>\n.opttw--optimistic .opttw__count--optimistic, .opttw--confirmed .opttw__count--confirmed, .opttw--rolled-back .opttw__count--rolled-back { display: inline; }\n.opttw--optimistic .opttw__like, .opttw--confirmed .opttw__like { color: var(--a); }\n.opttw--optimistic .opttw__note--optimistic, .opttw--confirmed .opttw__note--confirmed, .opttw--rolled-back .opttw__note--rolled-back { display: block; }\n</style>", "react": "export function OptimisticState({\n itemLabel = \"{{itemLabel}}\",\n stage = \"{{stage}}\",\n accent = \"{{accent}}\",\n baseLikes = {{baseLikes}},\n}) {\n const count = stage === \"rolled-back\" ? baseLikes : `${baseLikes} + 1`;\n const notes = {\n optimistic: \"UI updated instantly, before the server replied.\",\n confirmed: \"Server confirmed \\u2014 optimistic value was correct.\",\n \"rolled-back\": \"Server rejected the like \\u2014 UI rolled back to the real count.\",\n };\n return (\n <div role=\"status\" style={{ font: \"13px/1.5 system-ui, sans-serif\", color: \"#241430\", background: \"#FAF7F2\", padding: 18, borderRadius: 12, width: 300, boxSizing: \"border-box\" }}>\n <p style={{ margin: \"0 0 10px\", fontWeight: 700 }}>{itemLabel}</p>\n <div style={{ padding: 12, borderRadius: 8, background: \"#24143010\", textAlign: \"center\", fontSize: 20, fontWeight: 800, marginBottom: 10, color: stage !== \"rolled-back\" ? accent : \"#241430\" }}>♥ {count}</div>\n <p style={{ margin: 0, fontSize: 11, color: \"#24143099\" }}>{notes[stage]}</p>\n </div>\n );\n}" }
Save
History