From 321f981bdc0a12dd6fbd56e21cde94bb69473dec Mon Sep 17 00:00:00 2001 From: Thor-Herman <thorherman.eggelen@gmail.com> Date: Wed, 23 Sep 2020 11:01:52 +0200 Subject: [PATCH] Fix sessionStorage bug #10 Fixed bug with JSON syntax error on reloading a page with sessionstorage --- frontend/src/Components/ArtPage.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/Components/ArtPage.tsx b/frontend/src/Components/ArtPage.tsx index 464e4cd..2b1831e 100644 --- a/frontend/src/Components/ArtPage.tsx +++ b/frontend/src/Components/ArtPage.tsx @@ -35,8 +35,9 @@ class ArtPage extends React.Component<props, state> { const pageId = this.props.pageId.toString(); const choices = sessionStorage.getItem(pageId); // Previously stored options. Saved as string if (choices != null) { // We have stored something previously - const choicesObject = JSON.parse(choices); // Convert string to object - sessionStorage.setItem(pageId, {...choicesObject, [label]: choice}); // Update choices + const choicesObject: object = JSON.parse(choices); // Convert string to object + let choicesObjectStringified : string = JSON.stringify({...choicesObject, [label]: choice}); + sessionStorage.setItem(pageId, choicesObjectStringified); // Update choices } else sessionStorage.setItem(pageId, JSON.stringify({...this.state.options, [label]: choice})); }; -- GitLab