Browse Source

types update

main
zelleg 4 years ago
parent
commit
7dab157ca2
  1. 8
      src/App.tsx
  2. 11
      src/TodoItem.tsx

8
src/App.tsx

@ -2,7 +2,9 @@ import { useState } from 'react';
import { faker } from '@faker-js/faker'; import { faker } from '@faker-js/faker';
import { TodoItem } from './TodoItem'; import { TodoItem } from './TodoItem';
import { nanoid } from 'nanoid'; import { nanoid } from 'nanoid';
import { ReactElement } from 'react';
// interface elements types
interface My_items{ interface My_items{
label: string; label: string;
status: string; status: string;
@ -38,10 +40,10 @@ const initialList = [
...generateNTodo(10), ...generateNTodo(10),
]; ];
function App() :{TO_BE_DEFINED}{
function App() : ReactElement {
const [todoList, setTodoList] = useState(initialList); const [todoList, setTodoList] = useState(initialList);
const updater = (id:string, newStatus:string) => {
const updater = (id:string, newStatus:string) : void => {
setTodoList((oldList) => setTodoList((oldList) =>
oldList.map((it) => { oldList.map((it) => {
if (it.id !== id) { if (it.id !== id) {
@ -63,7 +65,7 @@ function App() :{TO_BE_DEFINED}{
key={item.id} key={item.id}
label={item.label} label={item.label}
status={item.status} status={item.status}
onChecked={(newState: string) => updater(item.id, newState)}
onChecked={(newState: string): void => updater(item.id, newState)}
/> />
))} ))}
</div> </div>

11
src/TodoItem.tsx

@ -1,6 +1,13 @@
import clsx from 'clsx'; import clsx from 'clsx';
import { ReactElement } from 'react';
export const TodoItem = ({ status, label, onChecked }) => {
interface My_items {
status: string;
label : string;
onChecked: (status: string) => void;
}
export const TodoItem = ({ status, label, onChecked } : My_items) : ReactElement => {
return ( return (
<div <div
className={clsx('p-4 flex items-center', { className={clsx('p-4 flex items-center', {
@ -17,7 +24,7 @@ export const TodoItem = ({ status, label, onChecked }) => {
disabled={status === 'archived'} disabled={status === 'archived'}
type="checkbox" type="checkbox"
className="rounded text-pink-500 ml-8 cursor-pointer disabled:cursor-not-allowed disabled:bg-black disabled:hover:bg-black" className="rounded text-pink-500 ml-8 cursor-pointer disabled:cursor-not-allowed disabled:bg-black disabled:hover:bg-black"
onChange={() => onChecked(status === 'open' ? 'done' : 'open')}
onChange={() : void => onChecked(status === 'open' ? 'done' : 'open')}
/> />
</div> </div>
); );

Loading…
Cancel
Save