awesome-compose/react-express-mongodb/frontend/src/components/TodoList.js
Jérémie Drouet e5828ad1bf react-express-mongodb: clean frontend code
- apply prettier style on every js file
- remove mutation on immutable variables
- remove wrapper on top of axios
- fix form handling
- remove useless port definition in dockerfile

Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
2020-05-13 11:33:48 +02:00

50 lines
945 B
JavaScript

import React from "react";
export default class TodoList extends React.Component {
constructor(props) {
super(props);
this.state = {
activeIndex: 0,
};
}
handleActive(index) {
this.setState({
activeIndex: index,
});
}
renderTodos(todos) {
return (
<ul className="list-group">
{todos.map((todo, i) => (
<li
className={
"list-group-item cursor-pointer " +
(i === this.state.activeIndex ? "active" : "")
}
key={i}
onClick={() => {
this.handleActive(i);
}}
>
{todo.text}
</li>
))}
</ul>
);
}
render() {
let { todos } = this.props;
return todos.length > 0 ? (
this.renderTodos(todos)
) : (
<div className="alert alert-primary" role="alert">
No Todos to display
</div>
);
}
}