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

react-use-stack-ref

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

react-use-stack-ref

a simple stack structure for react hooks

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

react-use-stack-ref

a simple stack structure for react hooks

live demo

npm packege


import React, { useState, useCallback, ChangeEvent } from 'react'
import { useStackRef } from 'react-use-stack-ref'

const App = (props: {}) => {
	const stack = useStackRef()
	const [input, setInput] = useState("")
	const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
		setInput(e.target.value)
	}
	const handlePush = useCallback(e => {
		stack.push(input)
		setInput("")
	}, [stack])
	const handlePop = useCallback(e => {
		const value = stack.pop()
		value && setInput(value as string)
	}, [stack])
	return (<>
		<h1>live demo for useStackRef</h1>
		<input type="text" value={input} onChange={handleChange} />
		<button onClick={handlePush} disabled={input.length === 0}>push</button>
		<button onClick={handlePop} disabled={stack.size === 0} >pop</button>
		<div>current value: {stack.value}</div>
		<div>stack depth: {stack.size}</div>
	</>)
}

export default App;

FAQs

Package last updated on 12 Aug 2020

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