New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-useonview

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-useonview

A react hook that returns a ref and does sth. when the element attached to that ref is scrolled into view.

latest
Source
npmnpm
Version
1.2.2
Version published
Weekly downloads
7
600%
Maintainers
1
Weekly downloads
 
Created
Source

react-useonview

A react hook that returns a ref and does sth. when the element attached to that ref is scrolled into view.

NPM JavaScript Style Guide

A react hook to trigger afunction when an component is scrolled into view. The given function will also be triggered on every subsequent scroll. So maybe add a closure to prevent this.

Install

npm install --save react-useonview

or

yarn add react-useonview

Usage

import React, { Component } from 'react';

import useOnView from 'react-useonview';

const App = () => {
  const [visible, setVisible] = useState(false);

  const trigger = useOnView(() => setVisible(true));

  return (
    <div>
      <div style={{ height: '100vh' }}></div>
      <div
        ref={trigger}
        style={{ opacity: visible ? '1' : '0', transition: '1s' }}
      >
        I appear when scrolled into view
      </div>
    </div>
  );
};

notes

  • the function will probably execute several times

  • does not care whether the element which has the ref attached is actually visible

  • also executes when scrolled past element

Api

Parameter in orderDescription
doSthfunction that is executed when ref-element scrolled in or past view
fullViewshould the object be in fullview to trigger doSth

options

namevaluesdefaultdescription
fullViewbooleanfalseshould doSth be triggered at first contact or when the element is in full view?

License

MIT © JustinHorn

Keywords

react

FAQs

Package last updated on 05 May 2021

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