Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@ module.exports = {
browser: true,
es2021: true,
},
extends: [
'plugin:react/recommended',
'airbnb',
],
extends: ['plugin:react/recommended', 'airbnb'],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
sourceType: 'module',
},
plugins: [
'react',
],
plugins: ['react'],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
Expand Down Expand Up @@ -45,8 +40,9 @@ module.exports = {
'object-curly-spacing': ['error', 'always'],
'key-spacing': ['error', { mode: 'strict' }],
'arrow-spacing': ['error', { before: true, after: true }],

'react/jsx-filename-extension': ['warn', { extensions: ['.js', '.jsx'] }],
'react/prop-types': 'off',
'react/react-in-jsx-scope': 'off',
'import/no-unresolved': 'off',
},
};
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"webpack-dev-server": "^4.8.1"
},
"dependencies": {
"nanoid": "^4.0.2",
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
Expand Down
36 changes: 36 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useState } from 'react';
import { nanoid } from 'nanoid';
import Header from './components/Header';
import TodoForm from './components/TodoForm';
import TodoLists from './components/TodoLists';

export default function App() {
const [newOrUpdateTodo, setNewOrUpdateTodo] = useState('');
const [todos, setTodos] = useState([]);

const handleSubmit = (e) => {
e.preventDefault();
setTodos([...todos, { id: nanoid(6), text: newOrUpdateTodo }]);
setNewOrUpdateTodo('');
};

const handleChange = (e) => {
setNewOrUpdateTodo(e.target.value);
};

const handleClickComplete = (clickedItemID) => {
setTodos(todos.filter((item) => item.id !== clickedItemID));
};

return (
<div>
<Header />
<TodoForm
newOrUpdateTodo={newOrUpdateTodo}
onSubmit={handleSubmit}
onChange={handleChange}
/>
<TodoLists todos={todos} onClickComplete={handleClickComplete} />
</div>
);
}
5 changes: 5 additions & 0 deletions src/components/Header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

export default function Header() {
return <div>TO-DO</div>;
}
5 changes: 5 additions & 0 deletions src/components/NoneTodos.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

export default function NoneTodos() {
return <span>할 일이 없어요!</span>;
}
16 changes: 16 additions & 0 deletions src/components/ShowTodos.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';

export default function ShowTodos({ todos, onClickComplete }) {
return (
<ol>
{todos.map(({ id, text }) => (
<li key={id}>
<span>{text}</span>
<button type="button" id={id} onClick={() => onClickComplete(id)}>
완료
</button>
</li>
))}
</ol>
);
}
10 changes: 10 additions & 0 deletions src/components/TodoForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

export default function TodoForm({ newOrUpdateTodo, onSubmit, onChange }) {
return (
<form onSubmit={onSubmit}>
<input type="text" value={newOrUpdateTodo} onChange={onChange} />
<button type="submit">추가</button>
</form>
);
}
12 changes: 12 additions & 0 deletions src/components/TodoLists.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import NoneTodos from './NoneTodos';
import ShowTodos from './ShowTodos';

const isEmpty = (arr = []) => arr.length === 0;

export default function TodoLists({ todos, onClickComplete }) {
if (isEmpty(todos)) {
return <NoneTodos />;
}
return <ShowTodos todos={todos} onClickComplete={onClickComplete} />;
}
5 changes: 5 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(<App />, document.getElementById('app'));