
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
react-easy-persist
Advanced tools
An easy hook to persist react state, support **web** and **react-native**,
An easy hook to persist react state, support web and react-native,
yarn add react-easy-persist
"peerDependencies": {
// the latest async-stoarge version alread support web
"@react-native-async-storage/async-storage": ">=1",
"ahooks": ">=3",
"react": ">=16.8"
}
usePersist
import * as React from 'react';
import { usePersist } from 'react-easy-persist';
export default function EasyPersistExample() {
const [count, setCount] = React.useState(0);
usePersist({ name: 'countdown', getValues: () => count, update: setCount });
function onIncrement() {
setCount(count + 1);
}
function onDecrement() {
setCount(count - 1);
}
return (
<div>
<h1>Countdown Persist Example</h1>
<h2>Count: {count}</h2>
<button onClick={onIncrement}>Increment +1</button>
<button onClick={onDecrement}>Decrement -1</button>
</div>
);
}
createUsePersist
import { createUsePersist } from 'react-easy-persist';
/**
* common hook, and you can create your own like this
*/
export const usePersist: ReturnType<typeof createUsePersist> = createUsePersist(
{
namePrefix: '@up',
debounce: 200,
encode: JSON.stringify,
decode: JSON.parse,
}
);
Persist formik
state:
import * as React from 'react';
import { useFormik } from 'formik';
import { usePersist } from 'react-easy-persist';
export default function FormikPersistExample() {
const formik = useFormik({
initialValues: {
username: '',
password: '',
},
onSubmit: values => {
alert(JSON.stringify(values));
},
});
const [clear, inited] = usePersist({
name: 'formik-example',
getValues: () => formik.values,
update: formik.setValues,
encode: JSON.stringify,
decode: JSON.Parse,
});
return (
<div>
<h1>useFormikPersist Example</h1>
<form
onSubmit={formik.handleSubmit}
onChange={formik.handleChange}
onReset={formik.handleReset}
onBlur={formik.handleBlur}
>
<input
type="text"
name="username"
placeholder="Username"
value={formik.values.username}
/>
<br />
<br />
<input
type="password"
name="password"
placeholder="Password"
value={formik.values.password}
/>
<br />
<br />
<div>
<button type="submit">Login</button>
<button type="reset">Reset</button>
<button
onClick={() => {
clear();
alert('clear cache done!');
}}
>
Clear Cache
</button>
</div>
</form>
</div>
);
}
Persist react useState
's state:
import * as React from 'react';
import { usePersist } from '../src';
export default function EasyPersistExample() {
const [count, setCount] = React.useState(0);
const [clear, inited] = usePersist({
name: 'countdown',
getValues: () => count,
update: setCount,
});
console.log(inited);
function onIncrement() {
setCount(count + 1);
}
function onDecrement() {
setCount(count - 1);
}
return (
<div>
<h1>Countdown Persist Example</h1>
<h2>Count: {count}</h2>
<button onClick={onIncrement}>Increment +1</button>
<button onClick={onDecrement}>Decrement -1</button>
</div>
);
}
FAQs
An easy hook to persist react state, support **web** and **react-native**,
We found that react-easy-persist demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.