diff --git a/src/components/RandomIDComponent.jsx b/src/components/RandomIDComponent.jsx index 95d3dc8..f865024 100644 --- a/src/components/RandomIDComponent.jsx +++ b/src/components/RandomIDComponent.jsx @@ -1,15 +1,32 @@ import React from "react"; +import { createStore } from 'zustand/vanilla' +import { persist, createJSONStorage } from 'zustand/middleware' import { getTranslation } from "../core/i18n/I18NHandler"; var randomId = 0; +export const participantIdLogState = createStore( + persist( + () => ({ + participant_id: "" + }), + { + name: 'participant-id-storage', // name of the item in the storage (must be unique) + storage: createJSONStorage(() => sessionStorage), // (optional) by default, 'localStorage' is used + }, + ), + ) + +const { getState, setState } = participantIdLogState; + function RandomIDComponent() { randomId = Math.floor(Math.random() * 89999) + 10000; + setState({ participant_id: "" + randomId }) return (

Your ID:

{randomId}

); } export function getUserID() { - return randomId; + return getState().participant_id; } export default RandomIDComponent; \ No newline at end of file