!question how can i explicitly give permission storage in plasmo
!question how can i explicitly give permission storage in plasmo
package.json file. "storage" permission to the "permissions" array in your package.json file. Here's an example:"storage" permission to the "permissions" array. This will allow your extension to use the storage API provided by Plasmo."storage" permission to your package.json file, you can use the @plasmohq/storage library to interact with the storage API. This library abstracts the persistent storage API available to browser extensions and falls back to localStorage when the extension storage API is unavailable.@plasmohq/storage library to store and retrieve data:useStorage hook from the @plasmohq/storage library to store and retrieve data. The useStorage hook takes two arguments: the key to use for storing the data, and the default value to use if there is no existing value for the key.@plasmohq/storage library and adding the "storage" permission to your package.json file, you can easily store and retrieve data in your Plasmo-based browser extension.pnpm create plasmo?/Users/brendanbuono/src/plasmo/cli/create-plasmopnpm unlink -g create-plasmopnpm create plasmo <- it uses the remote version of plasmoexamples directory"storage""storage""storage""storage""permissions""permissions"@plasmohq/storage@plasmohq/storage@plasmohq/storage@plasmohq/storageuseStorageuseStoragenpm install @plasmo/configpnpm create plasmopnpm create plasmo/Users/brendanbuono/src/plasmo/cli/create-plasmopnpm unlink -g create-plasmo🔵 INFO | Installing dependencies...
Scope: all 22 workspace projects
/Users/brendanbuono/src/plasmo/cli/create-plasmo:
ERR_PNPM_WORKSPACE_PKG_NOT_FOUND In ../../cli/create-plasmo: "@plasmo/config@workspace:*" is in the dependencies but no package named "@plasmo/config" is present in the workspaceexamples{
"name": "my-extension",
"version": "1.0.0",
"description": "My awesome extension",
"permissions": [
"storage"
],
"devDependencies": {
"@plasmohq/plasmo": "^1.0.0"
}
}import { useStorage } from '@plasmohq/storage';
const MyComponent = () => {
const [value, setValue] = useStorage('my-key', 'default-value');
const handleClick = () => {
setValue('new-value');
};
return (
<div>
<p>Current value: {value}</p>
<button onClick={handleClick}>Update value</button>
</div>
);
};