November 2019
Beginner
804 pages
20h 1m
English
Let's look at an example with a TodoList component that renders a set of TodoItem components:
import React from 'react';
export interface TodoItem {
id: string;
description: string;
done: boolean;
}
type Props = {
todo: TodoItem;
itemClicked: (id: string) => void;
};
export const TodoItem = (props: Props) => {
const {todo} = props;
return <li id={todo.id} onClick={() => props.itemClicked(todo.id)} style={{backgroundColor: 'gray', cursor: 'pointer'}}> {todo.description}</li>;
};
Our TodoItem component accepts two inputs:
Read now
Unlock full access