Git Product home page Git Product logo

use-pull's Introduction

usePull · codecov

usePull is a hook that will wrap a value with a ref and return a memoized callback that pulls the latest version of that value.

Installation

npm install --save use-pull

Usage

import React from 'react';
import usePull from 'use-pull';

function ExampleComponent({ id }) {
  const value = /* ... */;

  // wrap your value with `usePull`
  const getValue = usePull(value);
  // `usePull` will then return a memoized callback
  // that won't change references between renders

  // there are many reasons you'd want to do this:
  // - one reason is to preserve the reference of a callback by
  //   pulling the latest value at the time the callback is ran
  const handleSomething = useCallback(() => {
    const value = getValue();
  }, [getValue]);

  // - another reason may be to pull a value in an effect
  //   but not react to changes in that value
  useEffect(() => {
    const value = getValue();

    // do something with `value` and `id`...
  }, [id, getValue]);

  // ...
}

use-pull's People

Contributors

renovate-bot avatar ricokahler avatar renovate[bot] avatar dependabot-preview[bot] avatar dependabot[bot] avatar

Stargazers

Michael Demarais avatar

Watchers

Michael Demarais avatar  avatar  avatar

use-pull's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.