New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@newstudios/hook

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@newstudios/hook - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7

10

dist/useDevicePixelRatio.js
import { useState, useEffect } from 'react';
export function getDevicePixelRatio() {
var _window$devicePixelRa, _window;
return (_window$devicePixelRa = (_window = window) == null ? void 0 : _window.devicePixelRatio) != null ? _window$devicePixelRa : 1;
return typeof devicePixelRatio === 'number' ? devicePixelRatio : 1;
}

@@ -11,3 +9,3 @@ export function useDevicePixelRatio(ssr = false) {

const mqString = `(resolution: ${dpr}dppx)`;
const query = window.matchMedia(mqString);
const query = matchMedia(mqString);

@@ -17,6 +15,6 @@ const handleDPRChange = () => setDpr(getDevicePixelRatio());

handleDPRChange();
query.addListener(handleDPRChange);
return () => query.removeListener(handleDPRChange);
query.addEventListener('change', handleDPRChange, false);
return () => query.removeEventListener('change', handleDPRChange, false);
}, [dpr]);
return [dpr, setDpr];
}

3

dist/useNextUpdate.d.ts

@@ -0,1 +1,4 @@

/**
* useNextUpdate calls `next-tick` utility to execute the update hook
*/
export declare function useNextUpdate(): () => void;
import { useCallback, useEffect, useRef } from 'react';
import nextTick from 'next-tick';
import { useUpdate } from './useUpdate';
export function useNextUpdate() {
const ref = useRef(0);
const ref = useRef(false);
const forceUpdate = useUpdate();
useEffect(() => () => {
ref.current && clearTimeout(ref.current);
ref.current = false;
}, []);
return useCallback(() => {
if (!ref.current) {
ref.current = setTimeout(() => {
ref.current = 0;
forceUpdate();
ref.current = true;
nextTick(() => {
if (ref.current) {
ref.current = false;
forceUpdate();
}
});

@@ -15,0 +19,0 @@ }

@@ -10,5 +10,3 @@ "use strict";

function getDevicePixelRatio() {
var _window$devicePixelRa, _window;
return (_window$devicePixelRa = (_window = window) == null ? void 0 : _window.devicePixelRatio) != null ? _window$devicePixelRa : 1;
return typeof devicePixelRatio === 'number' ? devicePixelRatio : 1;
}

@@ -20,3 +18,3 @@

const mqString = `(resolution: ${dpr}dppx)`;
const query = window.matchMedia(mqString);
const query = matchMedia(mqString);

@@ -26,6 +24,6 @@ const handleDPRChange = () => setDpr(getDevicePixelRatio());

handleDPRChange();
query.addListener(handleDPRChange);
return () => query.removeListener(handleDPRChange);
query.addEventListener('change', handleDPRChange, false);
return () => query.removeEventListener('change', handleDPRChange, false);
}, [dpr]);
return [dpr, setDpr];
}

@@ -0,1 +1,4 @@

/**
* useNextUpdate calls `next-tick` utility to execute the update hook
*/
export declare function useNextUpdate(): () => void;

@@ -8,15 +8,22 @@ "use strict";

var _nextTick = _interopRequireDefault(require("next-tick"));
var _useUpdate = require("./useUpdate");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function useNextUpdate() {
const ref = (0, _react.useRef)(0);
const ref = (0, _react.useRef)(false);
const forceUpdate = (0, _useUpdate.useUpdate)();
(0, _react.useEffect)(() => () => {
ref.current && clearTimeout(ref.current);
ref.current = false;
}, []);
return (0, _react.useCallback)(() => {
if (!ref.current) {
ref.current = setTimeout(() => {
ref.current = 0;
forceUpdate();
ref.current = true;
(0, _nextTick.default)(() => {
if (ref.current) {
ref.current = false;
forceUpdate();
}
});

@@ -23,0 +30,0 @@ }

{
"name": "@newstudios/hook",
"version": "0.2.6",
"version": "0.2.7",
"description": "common hooks for react",

@@ -46,2 +46,3 @@ "main": "lib/index.js",

"@babel/preset-typescript": "^7.10.1",
"@types/next-tick": "^1.0.0",
"@types/react": "^16.9.38",

@@ -59,8 +60,7 @@ "@typescript-eslint/eslint-plugin": "^3.2.0",

},
"dependencies": {
"peerDependencies": {
"next-tick": "^1.1.0",
"react": "^16.13.1",
"resize-observer-polyfill": "^1.5.1"
},
"peerDependencies": {
"react": "^16.13.1"
},
"engines": {

@@ -67,0 +67,0 @@ "node": ">= 10.0.0"

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