
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
recallbackA React hook for creating cached callback.
Inspired by this RFC https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
with NPM
npm i recallback --save
with YARN
yarn add recallback
import useCallback from "recallback";
function Chat() {
const [text, setText] = useState("");
const onClick = useCallback(
() => {
sendMessage(text);
} /* no deps needed */
);
return <SendButton onClick={onClick} />;
}
Let say you have a todo list, and you want to handle toggle/remove action for each todo item, please check example below
import useCallback from "recallback";
function TodoList({ todos }) {
const handleToggleOf = useCallback((todoId) =>
// return a click callback for each todo item
// recallback will cache all callbacks
() => {
// do something
}
);
return todos.map((todo) => (
<TodoItem key={todo.id} id={todo.id} onToggle={handleToggleOf(todo.id)} />
));
}
By default, recallback uses first argument as callback, if the first argument is complex object, you can pass key selector to indicate which value is a key
import useCallback from "recallback";
function TodoList({ todos }) {
const handleToggleOf = useCallback(
(todo) => () => {},
// select todo id from todo object
(todo) => todo.id
);
return todos.map((todo) => (
<TodoItem key={todo.id} id={todo.id} onToggle={handleToggleOf(todo)} />
));
}
import { memo, ReactNode, useEffect, useState } from "react";
import useCallback from "recallback";
import "./styles.css";
const LoadContent = memo((props) => {
const [loading, setLoading] = useState(true);
console.log("re-render");
useEffect(() => {
setTimeout(setLoading, 10000, false);
}, [setLoading]);
// call children
return <div>{props.children(loading)}</div>;
});
export default function App() {
const [counter, setCounter] = useState(0);
const renderContent = useCallback((loading) => {
return <span>{loading && "Loading..."}</span>;
});
return (
<div className="App">
<button onClick={() => setCounter(counter + 1)}>
Counter: {counter}
</button>
<LoadContent>{renderContent}</LoadContent>
</div>
);
}
FAQs
A React hook for creating cached callback
We found that recallback 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.