Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

luciotbc/5-cwb-react-flow-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

5-cwb-react-flow-examples

References

Tutorial

Install Flow:

$ yarn add --dev flow-bin
$ yarn run flow init

Run Flow:

$ yarn flow

Add type to props:

type Props = {
  onSearchTermChange: string => void
};

Add type to state:

type State = {
  term: string
};

Add DefaultValue to state:

state = {
    term: ''
  };

Create Video Type:

type Video = {
  snippet: {
    title: string,
    thumbnails: {
      default: {
        url: string
      }
    }
  }
};

Add Video Type to props:

type Porps = {
  video: Video,
  onVideoSelect: Video => void
};

Ref props types in a function:

const VideoListItem = ({ video, onVideoSelect }: Porps) => {...

Create Video Type:

type Video = {
  etag: string,
  snippet: {
    title: string,
    thumbnails: {
      default: {
        url: string
      }
    }
  }
};

type Props = {
  videos: Array<Video>,
  onVideoSelect: Video => void
};

Export shared types:

//@flow
export type Video = {
  etag: string,
  snippet: {
    title: string,
    thumbnails: {
      default: {
        url: string
      }
    }
  }
};

Import shared types:

import type { Video } from '../model'

flow everywhere

To Clicks:

  const videoSelected = (e: SyntheticEvent<EventTarget>) => {
    e.preventDefault();
    props.onVideoSelect(props.video);
  };

};

To Inputs:

  videoSelected = (e: SyntheticInputEvent<EventTarget>) => {
    e.preventDefault();
    this.onInputChange(e.target.value);
  };

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages