UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 842 B
{ "version": 3, "sources": ["../../src/hooks/use-cached-truthy.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\n\n/**\n * Keeps an up-to-date copy of the passed value and returns it. If value becomes falsy, it will return the last truthy copy.\n *\n * @param {any} value\n * @return {any} value\n */\nexport function useCachedTruthy( value ) {\n\tconst [ cachedValue, setCachedValue ] = useState( value );\n\tuseEffect( () => {\n\t\tif ( value ) {\n\t\t\tsetCachedValue( value );\n\t\t}\n\t}, [ value ] );\n\treturn cachedValue;\n}\n"], "mappings": ";AAGA,SAAS,UAAU,iBAAiB;AAQ7B,SAAS,gBAAiB,OAAQ;AACxC,QAAM,CAAE,aAAa,cAAe,IAAI,SAAU,KAAM;AACxD,YAAW,MAAM;AAChB,QAAK,OAAQ;AACZ,qBAAgB,KAAM;AAAA,IACvB;AAAA,EACD,GAAG,CAAE,KAAM,CAAE;AACb,SAAO;AACR;", "names": [] }