{"version":3,"sources":["../../src/MappedController/index.ts"],"names":["useMappedValue_default"],"mappings":";;;;;AAkBA,IAAM,gBAAA,GAoBF,CAAC,KAAA,KACH,KAAM,CAAA,MAAA,CAAOA,yCAAe,KAAM,CAAA,KAAA,EAAO,KAAM,CAAA,MAAM,CAAC,CAAA;AAExD,IAAO,wBAAQ,GAAA","file":"chunk-EDO3DJEW.cjs","sourcesContent":["import type { FC } from 'react';\nimport type { AsyncState, StateBase as State } from '../types';\nimport useMappedValue from '../useMappedValue';\n\ntype Props<S extends State, V> = {\n  state: S;\n  /** Function that maps the {@link Props.state state’s} value. */\n  mapper(\n    ...args: S extends AsyncState<infer T, infer E>\n      ? [value: T | undefined, isLoaded: boolean, error: E | undefined]\n      : S extends State<infer T>\n        ? [value: T]\n        : never\n  ): V;\n  /** Function to render the mapped value. */\n  render(mappedValue: V): ReturnType<FC>;\n};\n\nconst MappedController: {\n  /**\n   * A controller that {@link mapper maps} a value from {@link Props.state state} and passes it to a {@link Props.render render} function.\n   * This component serves as a wrapper for the {@link useMappedValue} hook.\n   * @example\n   * ```jsx\n   * <MappedController\n   *   state={state}\n   *   mapper={(value) => value % 2}\n   *   render={(isEven) => <span>{isEven ? 'even' : 'odd'}</span>}\n   * />\n   *\n   * <MappedController\n   *   state={asyncState}\n   *   mapper={(value, isLoaded) => !isLoaded || !!value }\n   *   render={(isRenderable) => isRenderable && <Component />}\n   * />\n   * ```\n   */\n  <S extends State, V>(props: Props<S, V>): ReturnType<FC>;\n} = (props: Props<any, any>) =>\n  props.render(useMappedValue(props.state, props.mapper));\n\nexport default MappedController;\n"]}