refun
Version:
A collection of React Hook-enabled functions that compose harmoniously with each other. Similar to `recompose`, but:
1 lines • 1.11 kB
Source Map (JSON)
{"version":3,"sources":["map-default-context.ts"],"names":["mapDefaultContext","context","props","contextProps","mergedProps","key","UNDEFINED"],"mappings":";;;;;;;;;AAAA;;AAEA;;AAEO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB,CAAiBC,OAAjB;AAAA,SAA0C,UAAeC,KAAf,EAAoC;AAC7G,QAAMC,YAAY,GAAG,uBAAWF,OAAX,CAArB;AACA,QAAMG,WAAW,8BAAQF,KAAR,CAAjB;;AAGA,SAAK,IAAMG,GAAX,IAAkBF,YAAlB,EAAgC;AAC9B,UAAKD,KAAD,CAAeG,GAAf,MAAwBC,eAA5B,EAAuC;AACrCF,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"}