0% found this document useful (0 votes)
8 views2 pages

Itemstodo

Uploaded by

Dylan Chaos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Itemstodo

Uploaded by

Dylan Chaos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/* eslint-disable react/prop-types */

/* eslint-disable react/destructuring-assignment */
/* eslint-disable react/button-has-type */
import React, { useState, useEffect } from 'react';
import { FaTrash } from 'react-icons/fa';
import styles from './TodoItem.module.scss';

const TodoItem = (props) => {


const [editing, setEditing] = useState(false);

const handleEditing = () => {


setEditing(true);
};

const handleUpdatedDone = (event) => {


if (event.key === 'Enter') {
setEditing(false);
}
};

const completedStyle = {
fontStyle: 'italic',
color: '#595959',
opacity: 0.4,
textDecoration: 'line-through',
};

const { completed, id, title } = props.todo;

const viewMode = {};


const editMode = {};

if (editing) {
viewMode.display = 'none';
} else {
editMode.display = 'none';
}

useEffect(() => () => {


console.log('Cleaning up...');
}, []);

return (
<li className={styles.item}>
<div onDoubleClick={handleEditing} style={viewMode}>
<input
type="checkbox"
className={styles.checkbox}
checked={completed}
onChange={() => props.handleChangeProps(id)}
/>
<button onClick={() => props.deleteTodoProps(id)}>
<FaTrash style={{ color: 'orangered', fontSize: '16px' }} />
{' '}
</button>
<span style={completed ? completedStyle : null}>{title}</span>
</div>
<input
type="text"
style={editMode}
className={styles.textInput}
value={title}
onChange={(e) => {
props.setUpdate(e.target.value, id);
}}
onKeyDown={handleUpdatedDone}
/>
</li>
);
};

export default TodoItem;

You might also like