Socket
Book a DemoInstallSign in
Socket

@ndla/hooks

Package Overview
Dependencies
Maintainers
6
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndla/hooks

Collection of React hooks used by NDLA

latest
Source
npmnpm
Version
2.1.16
Version published
Weekly downloads
12
-95.02%
Maintainers
6
Weekly downloads
 
Created
Source

Hooks

Collection of React hooks used by NDLA

Table of Contents

  • Installation
  • Usage

Installation

$ yarn @ndla/hooks

Usage

useComponentSize

import { useRef } from "react";
import useComponentSize from "@ndla/component-size";

function MyComponent() {
  let ref = useRef(null);
  let size = useComponentSize(ref);
  // size == { width: 100, height: 200 }
  let { width, height } = size;
  let imgUrl = `https://via.placeholder.com/${width}x${height}`;

  return (
    <div style={{ width: "100%", height: "100%" }}>
      <img ref={ref} src={imgUrl} />
    </div>
  );
}

useWindowSize

import useWindowSize from "@ndla/window-size";

function MyComponent() {
  let windowSize = useWindowSize(100); // Optional throttle wait time (in ms)
  // {
  //   innerWidth: window.innerWidth,
  //   innerHeight: window.innerHeight,
  //   outerWidth: window.outerWidth,
  //   outerHeight: window.outerHeight,
  // }
  return (
    <div>
      {windowSize.innerWidth < 768 ? (
        <p>This document is less than 768px wide.</p>
      ) : (
        <p>The document is at least 768px wide.</p>
      )}
    </div>
  );
}

Keywords

ndla

FAQs

Package last updated on 10 Dec 2025

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