const WrapperWidget = ({ children, id, storageType }) => { // This function handles the state change for the children widgets const handleStateChange = (key, value) => { // Use the unique identifier to create a unique storage key const storageKey = `${id}_${key}`; if (storageType === "local") { // Update the local storage with the new state localStorage.setItem(storageKey, JSON.stringify(value)); } else if (storageType === "sync") { // Update the sync storage with the new state // Replace this with the appropriate API call for your sync storage syncStorage.setItem(storageKey, JSON.stringify(value)); } }; // This function initializes the state of the children widgets const initState = (key, defaultValue) => { // Use the unique identifier to create a unique storage key const storageKey = `${id}_${key}`; let storedValue; if (storageType === "local") { storedValue = localStorage.getItem(storageKey); } else if (storageType === "sync") { // Retrieve the value from sync storage // Replace this with the appropriate API call for your sync storage storedValue = syncStorage.getItem(storageKey); } if (storedValue) { return JSON.parse(storedValue); } return defaultValue; }; // Render the children widgets and pass the state management functions as props return React.Children.map(children, (child) => React.cloneElement(child, { handleStateChange, initState }) ); };