UNPKG

refun

Version:

A collection of React Hook-enabled functions that compose harmoniously with each other. Similar to `recompose`, but:

1 lines 1.18 kB
{"version":3,"sources":["map-default-context.ts"],"names":["useContext","UNDEFINED","mapDefaultContext","context","props","contextProps","mergedProps","key"],"mappings":"AAAA,SAASA,UAAT,QAA2B,OAA3B;AAEA,SAASC,SAAT,QAA0B,MAA1B;AAEA,OAAO,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAAiBC,OAAjB;AAAA,SAA0C,UAAeC,KAAf,EAAoC;AAC7G,QAAMC,YAAY,GAAGL,UAAU,CAACG,OAAD,CAA/B;AACA,QAAMG,WAAW,qBAAQF,KAAR,CAAjB,CAF6G,CAI7G;;AACA,SAAK,IAAMG,GAAX,IAAkBF,YAAlB,EAAgC;AAC9B,UAAKD,KAAD,CAAeG,GAAf,MAAwBN,SAA5B,EAAuC;AACrCK,QAAAA,WAAW,CAACC,GAAD,CAAX,GAAmBF,YAAY,CAACE,GAAD,CAA/B;AACD;AACF;;AAED,WAAOD,WAAP;AACD,GAZgC;AAAA,CAA1B","sourcesContent":["import { useContext } from 'react'\nimport type { Context } from 'react'\nimport { UNDEFINED } from 'tsfn'\n\nexport const mapDefaultContext = <CP extends {}> (context: Context<CP>) => <P extends {}>(props: P): CP & P => {\n const contextProps = useContext(context)\n const mergedProps = { ...props } as any\n\n // eslint-disable-next-line guard-for-in\n for (const key in contextProps) {\n if ((props as any)[key] === UNDEFINED) {\n mergedProps[key] = contextProps[key]\n }\n }\n\n return mergedProps\n}\n"],"file":"map-default-context.js"}