DEV Community

Discussion on: Data fetching in React the functional way powered by TypeScript, io-ts & fp-ts

Collapse
 
austinrivas profile image
Austin Rivas • Edited

Ok, I can see that the fp-ts api was changed during the 2.0 update.

bimap is now its own function and not a property of Either anymore.

It seems the correct implementation is now:

export class Remote<T> extends React.Component<RemoteProps<T>, RemoteState> {

  public render() {
    return (
      <React.Fragment>
        {
          pipe(this.props.data, fold(
          l => {
            if (l === null) {
              return this.props.loading();
            } else {
              return this.props.error(l);
            }
          },
          r => {
            return this.props.success(r);
          }))
        }
      </React.Fragment>
    );
  }
}
Enter fullscreen mode Exit fullscreen mode

@remojansen do you agree with this implementation?

Collapse
 
josuevalrob profile image
Josue Valenica

gracias!