@hashicorp/react-boolean-input
Advanced tools
Comparing version 1.0.1 to 1.0.2
14
index.js
@@ -21,7 +21,12 @@ import React, { useState, useEffect } from 'react' | ||
// set up state for the input value | ||
const [stateValue, setValue] = useState(value || false) | ||
const [stateValue, setValue] = useState(false) | ||
const [isDirty, setIsDirty] = useState(false) | ||
// if the parent changes the value, reflect it to state | ||
useEffect(() => setValue(value), [value]) | ||
// if the state changes the value, reflect it to the parent | ||
useEffect(() => onValueChange && onValueChange(stateValue), [stateValue]) | ||
useEffect(() => { | ||
// if the input hasn't been touched, don't pass up the value | ||
if (!isDirty) return | ||
return onValueChange && onValueChange(stateValue) | ||
}, [stateValue]) | ||
// generate a uid to pair the label to the input | ||
@@ -44,3 +49,6 @@ const uid = useUID() | ||
value={stateValue} | ||
onChange={e => setValue(e.target.checked)} | ||
onChange={e => { | ||
setIsDirty(true) | ||
return setValue(e.target.checked) | ||
}} | ||
/> | ||
@@ -47,0 +55,0 @@ <label htmlFor={`id-${name}-${uid}`}> |
{ | ||
"name": "@hashicorp/react-boolean-input", | ||
"description": "A checkbox input", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "dist", | ||
@@ -18,3 +18,3 @@ "dependencies": { | ||
}, | ||
"gitHead": "5e68e058130d4c2fa54017babdae06568acff6be" | ||
"gitHead": "2f16ae732cb52aebad1e0e533952c6b526ac7701" | ||
} |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
28390
362