Lifts a function that maps the prop type B into the prop type A, into a function the maps a component of type FC<A> into a component of type FC<B>.
B
A
FC<A>
FC<B>
This is the opposite of how map works. For example, Array.map lifts:
map
Array.map
(A ⇒ B) -into→ (Array<A> ⇒ Array<B>) Copy
(A ⇒ B) -into→ (Array<A> ⇒ Array<B>)
While mapProps, calledmapInput in effect, and contramap in @effect/typeclass, (“contra” means “counter to” in greek), is of type:
mapProps
mapInput
effect
contramap
@effect/typeclass
(B ⇒ A) -into→ (FC<A> ⇒ FC<B>) Copy
(B ⇒ A) -into→ (FC<A> ⇒ FC<B>)
Useful when:
For example:
import {mapProps} from 'react-compinators'interface B { foo: string }interface A { bar: number }const ComponentA: FC<A> = ({ bar }) => <div>{bar + 1}</div>;// The function mapping B ⇒ Aconst mapper = (a: B): A => ({ bar: a.foo.length })// We now have a component of Bconst ComponentB: FC<B> = pipe(ComponentA, mapProps(mapper)); Copy
import {mapProps} from 'react-compinators'interface B { foo: string }interface A { bar: number }const ComponentA: FC<A> = ({ bar }) => <div>{bar + 1}</div>;// The function mapping B ⇒ Aconst mapper = (a: B): A => ({ bar: a.foo.length })// We now have a component of Bconst ComponentB: FC<B> = pipe(ComponentA, mapProps(mapper));
Lifts a function that maps the prop type
Binto the prop typeA, into a function the maps a component of typeFC<A>into a component of typeFC<B>.This is the opposite of how
mapworks. For example,Array.maplifts:While
mapProps, calledmapInputineffect, andcontramapin@effect/typeclass, (“contra” means “counter to” in greek), is of type:Useful when:
A.B.B.B⇒A.For example: