Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
import { useState, useCallback } from 'react';
/**
* Custom hook for managing background state
*/
export function useBackgroundState() {
const [backgroundData, setBackgroundData] = useState({
url: '',
style: '',
type: '',
currentAPI: '',
video: false,
photoInfo: {
hidden: false,
offline: false,
photographerURL: '',
photoURL: '',
},
});
const updateBackground = useCallback((newData) => {
setBackgroundData((prev) => ({
...prev,
...newData,
// A new background brings its own metadata: replace, never merge, so
// flags such as `hidden` from the previous one cannot leak into it.
photoInfo: newData.photoInfo ? { ...newData.photoInfo } : prev.photoInfo,
}));
}, []);
const resetBackground = useCallback(() => {
setBackgroundData({
url: '',
style: '',
type: '',
currentAPI: '',
video: false,
photoInfo: { hidden: true },
});
}, []);
return {
backgroundData,
updateBackground,
resetBackground,
};
}