Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
uselocalstoragenextjs
Advanced tools
This is a library that provides an easy way to manage localStorage, having the possibility to connect changes through different components.
Using npm:
npm i uselocalstoragenextjs
import { useLocalStorage } from "uselocalstoragenextjs";
const {
value, //Value of element in localStorage
setLocalStorage, //function for modify localStorage
load, //if the value has been loaded or not
} = useLocalStorage({
name: "cart", //name of element in localStorage
defaultValue: [], //defaulValue if element in localStorage if null
parse: (v: any) => {
//function for modify value after get of localStorage
return JSON.parse(v == "" ? "[]" : v);
},
updateValue(oldValue, newValue) {
//function for modify value before set of localStorage
return [...oldValue, newValue];
},
});
import { useLocalStorage } from "uselocalstoragenextjs";
import Component from "./component";
const Home = () => {
const { value, setLocalStorage, load } = useLocalStorage({
name: "cart",
defaultValue: [],
parse: (v: any) => {
return JSON.parse(v == "" ? "[]" : v);
},
updateValue(olValue, newValue) {
return [...olValue, newValue];
},
});
return (
<div>
Cart
<div>{JSON.stringify(value)}</div>
<br />
<button
onClick={() => {
setLocalStorage({ p: 1 });
}}
>
Add New Product
</button>
<Component />
</div>
);
};
export default Home;
import { useLocalStorage } from "uselocalstoragenextjs";
export default () => {
const { value, load } = useLocalStorage({
name: "cart",
defaultValue: [],
parse: (v: any) => {
return JSON.parse(v == "" ? "[]" : v);
},
});
return (
<>
{load && (
<>
N Items in Cart
<br />
{value.length}
</>
)}
</>
);
};
//interface of value
interface notification_interface {
type?: "ok" | "error" | "warning";
msg?: string;
}
const {
value, //Value of element in localStorage
setLocalStorage, //function for modify localStorage
load, //if the value has been loaded or not
} = useLocalStorage<notification_interface>({
name: "notification", //name of element in localStorage
defaultValue: {}, //defaulValue if element in localStorage if null
parse: (v: any) => {
//function for modify value after get of localStorage
return JSON.parse(v == "" ? "{}" : v);
},
});
Email blancofrancisco34@gmail.com
FAQs
Create hook useLocalStorage for NextJs
The npm package uselocalstoragenextjs receives a total of 279 weekly downloads. As such, uselocalstoragenextjs popularity was classified as not popular.
We found that uselocalstoragenextjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.