-
I am trying to implement session storage for a input, much as demonstrated here: The only difference is that I would like to create the inputs and place it in HTML. Here is my setup:
IssueThe code above works and the session object is placed in the session object. Reading the and parsing the session object also works, but as soon I change the value from:
to
The radio buttons render without default value. I assume it has to do with the order things are executed. Is there any way out? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
The issue here is that const value = dateRanges.find((d) => JSON.stringify(d) === sessionStorage.getItem("dateRangeType")) ?? dateRanges[0]; |
Beta Was this translation helpful? Give feedback.
-
Ahhh! Of course. Then it will be even easier to just store the value in the session object const dateRanges = [
{ name: "Last 28 days", value: "28-dd" },
{ name: "Last month", value: "last-mm" },
{ name: "Last quarter", value: "last-qq" },
];
const sessionValue = dateRanges.find(d => d.value === sessionStorage.getItem("dateRangeType"))
const dateRangeInputs = Inputs.radio(dateRanges, {
format: (x) => x.name,
value: sessionValue ?? dateRanges[0],
});
const selectedDateRange = view(dateRangeInputs); if (selectedDateRange) {
sessionStorage.setItem("dateRangeType", selectedDateRange.value);
} Thanks again!! |
Beta Was this translation helpful? Give feedback.
The issue here is that
JSON.parse(JSON.stringify({x}))
is not strictly equal to{x}
: it's a different object. Instead, you could compare the string representations: