尝试导入错误:未从“下划线”导出“ _”

时间:2020-09-06 15:46:11

标签: reactjs redux

我不断收到以下消息,但我不知道如何纠正它: 尝试导入错误:未从“下划线”中导出“ _”

我确实运行了npm install --save下划线,但这不能解决问题。

这是我正在使用的文件:

import React from 'react'
import { connect } from 'react-redux'
import { _ } from 'underscore'
import { FILTER_ALL, FILTER_COMPLETED } from '../redux/actionTypes'
import { toggleTodo } from '../redux/actions'

const Todo = ({ todo, id, toggleTodo }) => (
    <li className={todo.completed ? 'completed' : ''} onClick={() => toggleTodo(id)}>{todo.content}</li>
)

function TodoList({ todos, toggleTodo }) {
    return (
        _.keys(todos).map((id) => (
            <Todo key={id} id={id} toggleTodo={toggleTodo} todo={todos[id]} />
        ))
    )
}

const mapState = (state) => {
    if (state.visibilityFilter.activeFilter === FILTER_ALL) {
        return { todos: state.todos.data }
    } else if (state.visibilityFilter.activeFilter === FILTER_COMPLETED) {
        return ({
            todos: _.pick(state.todos.data, (todo) => todo.completed)
        })
    } else {
        return ({
            todos: _.pick(state.todos.data, (todo) => !todo.completed)
        })
    }
}

export default connect(mapState, { toggleTodo })(TodoList);

1 个答案:

答案 0 :(得分:0)

您是否尝试过执行此操作:import * as _ from 'underscore'

在此处查看文档:{​​{3}}

_.map(things, thing => {
    ...
})