UNPKG

zigbee2mqtt-windfront

Version:

[![Version](https://img.shields.io/npm/v/zigbee2mqtt-windfront.svg)](https://npmjs.org/package/zigbee2mqtt-windfront) [![CI](https://github.com/Nerivec/zigbee2mqtt-windfront/actions/workflows/ci.yml/badge.svg)](https://github.com/Nerivec/zigbee2mqtt-windf

2 lines (1 loc) 615 B
import{r as e,j as l}from"./index-C9teBVht.js";const x=e.memo(({value:n,onChange:o,debounce:c=500,...f})=>{const[t,s]=e.useState(n.toString()),a=e.useRef(!1),u=e.useRef(void 0);e.useEffect(()=>{s(n.toString())},[n]),e.useEffect(()=>{if(u.current===t)return;if(a.current===!1){u.current=t,a.current=!0;return}const r=setTimeout(()=>{u.current!==t&&(u.current=t,o(t))},c);return()=>clearTimeout(r)},[t,c,o]);const p=e.useCallback(r=>{s(r.target.value)},[]),m=e.useCallback(r=>{r.key==="Escape"&&(r.preventDefault(),s(""))},[]);return l.jsx("input",{...f,type:"text",value:t,onChange:p,onKeyDown:m})});export{x as D};