Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kill-use-callback

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kill-use-callback

React withStable HOC

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

kill-use-callback

npm npm bundle size npm type definitions GitHub

This package provides memorized callbacks (like useCallback) for any callbacks like it's inline or in a condition or loop.

Please ⭐ star this repo if it's useful!

import React from "react";
import { propsAreEqual, depFn, useEffect } from "./kill-use-callback";

const Child = React.memo(
  ({getText}) => <div>{getText()}</div>,
  propsAreEqual);

export default function App({items}) {
  const [text, setText] = React.useState("a");
  const [text2, setText2] = React.useState("b");

  const getText = depFn((prefix) => `${prefix}: ${text}`, [text]);
  useEffect(() => {
    console.log(getText("Effect"));
  }, [getText]);

  return (
    <div>
      {items.map(item => (
        <Child getText={depFn(() => `${item}: ${text}`, [text])} />
      ))}
    </div>
  );
}

When text2 changes, Child won't re-render and the effect won't re-trigger.
And text changes, Child will re-render and the effect will re-trigger.

Demo

Please check this codesandbox example.

Keywords

FAQs

Package last updated on 03 Jun 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc