
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
@rkmodules/use-inner
Advanced tools
This is a very simple wrapper around Reacts useState
. The entire implementation is this:
export const useInner = <T>(
outer: T,
watch?: any[]
): [T, React.Dispatch<React.SetStateAction<T>>] => {
let [inner, setInner] = React.useState<T>(outer);
React.useEffect(() => {
setInner(outer);
}, watch || [outer]);
return [inner, setInner];
};
use useInner
as a local shallow copy of some prop from outside. One place I use this a lot is where a default value is given through props (which may change), but there is also an inner state.
npm install @rkmodules/use-inner
import useInner from "@rkmodules/use-inner";
function LazyInput({ value, onChange }) {
let [inner, setInner] = useInner(value);
// inner now changes whenever value changes, but also on setInner
const handleChange = (e) => {
setInner(e.target.value);
};
const handleBlur = (e) => {
onChange(inner);
};
return <input value={inner} onChange={handleChange} onBlur={handleBlur} />;
}
function LazyArray({ value, onChange }) {
let [inner, setInner] = useInner(value.toUpperCase(), [value]);
// inner now changes whenever value changes, but also on setInner. In this cases also when capitalization changes
const handleChange = (e) => {
setInner(e.target.value);
};
const handleBlur = (e) => {
onChange(inner);
};
return <input value={inner} onChange={handleChange} onBlur={handleBlur} />;
}
# project setup
followed https://www.twilio.com/blog/2017/06/writing-a-node-module-in-typescript.html for project setup
FAQs
internal state react hook that follows an outside state
We found that @rkmodules/use-inner 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.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.