2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TypeScriptのcomponentsの書き方

JavaScriptでは型定義がない。

このため、通常はJSDocコメントを使用して型情報を提供するか、動的型付けのまま進行

今回は動的型付けのまま進行

export const IncompleteTodos = () => {
  const  [todos, onClickComplete, onCLickDelete] = props

type キーワードを使ってプロパティの型を定義

type IncompleteTodosProps = {
  todos: string[];
  onClickComplete: (index: number) => void;
  onClickDelete: (index: number) => void;
};

型注釈がないため、動的型付けのまま進行

export const IncompleteTodos = (props) => {

IncompleteTodosコンポーネントがIncompleteTodosProps型のプロパティを受け取るのを指定

React.FC<IncompleteTodosProps>は、IncompleteTodosProps型を持つReact関数コンポーネントを定義

参考動画
最新ver対応済】モダンJavaScriptの基礎から始める挫折しないためのReact入門

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?