diff --git a/lib/page-with-shareable-state.tsx b/lib/page-with-shareable-state.tsx index d03d129..da6e424 100644 --- a/lib/page-with-shareable-state.tsx +++ b/lib/page-with-shareable-state.tsx @@ -86,15 +86,17 @@ export function createPageWithShareableState({ /** The default state from the URL, which we'll pass into our component. */ let defaults: T = defaultValue; - let deserializeError = false; + let didDeserializeThrow = false; try { defaults = deserialize(state || ""); } catch (e) { console.log(`Error deserializing state: ${e}`); - deserializeError = true; + didDeserializeThrow = true; } + const [showError, setShowError] = useState(didDeserializeThrow); + const onChange = useCallback( (value: T) => { const newState = serialize(value); @@ -119,7 +121,7 @@ export function createPageWithShareableState({ return ( <> - {deserializeError && ( + {showError && (

@@ -130,7 +132,7 @@ export function createPageWithShareableState({ Either its data is corrupted, or displaying it is no longer supported.

- +
)}