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.
react-autosaver
Advanced tools
Simple higher-order functions and hooks to manage auto-saving in React
⚠️ This library is currently pre-release and the API is subject to change without warning!
Consider using this component if:
Exposes a component called AutoSaver
that has a prop onAutosaveTriggered
which allows you to specify a callback whenever the component determines that auto save should occur
Exposes a component called WatchChanges
which can be placed as a child of the parent AutoSaver
. This component can bind to inputs using React refs and triggers whenever the following happens:
onChange
callback fires and then becomes idledidChangeHappen
callback function is manually calledAllows configuring a global auto-save delay for the onAutosave
callback
Allows configuring auto-save delays per WatchChanges
instance, so you can fine tune exactly how soon or late the autosave event is triggered on per-component basis
Allows toggling on/off an autosave loop
Install the library using a package manager of your choice:
# npm
npm i react-autosaver --save
# yarn
yarn add react-autosaver
Import components as needed:
import { AutoSave } from 'react-autosaver';
react-autosaver
has the following peer dependencies:
"prop-types": "^15.7.2"
"react": "^16.8.0"
"react-dom": "^16.8.0"
import React, { useState, useCallback } from 'react';
import { AutoSave, WatchChanges } from 'react-autosaver';
export default function App() {
const [isSaving, setIsSaving] = useState(false);
const callback = useCallback(() => {
console.log('Lets autosave now!');
}, []);
return (
<AutoSave
isAutosaving={isSaving}
enableAutosaveLoop
onAutosaveTriggered={callback}
/>
);
}
WatchChanges
import React, { useState, useCallback } from 'react';
import { AutoSave, WatchChanges } from 'react-autosaver';
export default function App() {
const [input, setInput] = useState('');
const [isSaving, setIsSaving] = useState(false);
const triggerAutoSave = useCallback(() => {
console.log('Lets autosave now!');
}, []);
const onInputChange = (e) => {
setInput(e.target.value);
};
return (
<AutoSave isAutosaving={isSaving} onAutosaveTriggered={triggerAutoSave}>
<WatchChanges triggerMode="BLUR">
{({ autosaveInputRef }) => {
return (
<>
<label>I trigger autosave on blur</label>
<input
ref={autosaveInputRef}
value={input}
onChange={onInputChange}
/>
</>
);
}}
</WatchChanges>
</AutoSave>
);
}
WatchChanges
exposes a didChangeHappen
callback function which you can call manually. You are not restricted to using inputs bound with a ref, and can manually trigger autosave whenever you determine a save should occur based on your application logic.
<WatchChanges triggerMode="IDLE" inputInputIdleDelay={1500}>
{({ didChangeHappen }) => {
return (
<>
<label>Custom input which autosaves manually</label>
<input
onChange={() => {
didChangeHappen();
}}
/>
</>
);
}}
</WatchChanges>
// TODO
// TODO
FAQs
Simple higher-order functions and hooks to manage auto-saving in React
We found that react-autosaver 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
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.