最佳答案
new to ES6, I was trying to make a React simple functional component like this
// ./Todo.jsx
export default const Todo = ({
todos,
onTodoClick,
}) => (
<ul>
{todos.map( (todo, i) =>
<li key = {i}
onClick = {() => onTodoClick(i) }
style = {{textDecoration: todo.completed ? 'line-through': 'none' }}
>
{todo.text}
</li>
)}
</ul>
)
But
// Another file
import Todo from './Todos.jsx';
console.log(Todo) // undefined
did not yield the arrow function.
but if I leave off the "const todo =" part in the export link, like so
export default ({
todos,
onTodoClick,
}) => (...)
It gets successfully imported.
Why is that?