Parsing error: Identifier 'action' h been declared

来源:5-8 使用 actionCreator 统一创建 action

qq_慕工程2524350

2020-02-23

对照老师的,一模一样啊,不知道问题出在哪里了。。
代码如下:
import React, { Component } from ‘react’;
import ‘antd/dist/antd.css’;
import { Input, Button, List } from ‘antd’;
import store from './store/index.js’
import { getInputChangeAction, getAddItemAction, getDeleteItemAction } from ‘./store/actionCreators5.8’

class TodoList extends Component {

constructor(props) {
super(props);
this.state = store.getState();
this.handleInputChange = this.handleInputChange.bind(this);
this.handleStoreChange = this.handleStoreChange.bind(this);
this.handleBtnClick = this.handleBtnClick.bind(this);
store.subscribe(this.handleStoreChange); //store的内容只要改变,括号中函数就执行。
}

render() {
return (
<div style={{marginTop: ‘10px’, marginLeft: ‘10px’}}>


<Input
value={this.state.inputValue}
placeholder='待办事项’
style={{width: ‘300px’, marginRight: ‘10px’ }}
onChange={this.handleInputChange}
/>
提交

<List
style={{marginTop: ‘10px’, width: ‘300px’}}
bordered
dataSource={this.state.list}
renderItem={(item, index) => (
<List.Item onClick={this.handleItemDelete.bind(this, index)}>
{item}
</List.Item>
)}
/>

)
}

handleInputChange(e) {
const action = getInputChangeAction(e.target.value);
store.dispatch(action);
}

handleStoreChange() {
this.setState(store.getState())
}

handleBtnClick() {
const action = getAddItemAction();
store.dispatch(action);
}

handleItemDelete(index) {
const action = getDeleteItemAction(index);
store.dispatch(action);
}

}

export default TodoList;

写回答

1回答

Dell

2020-02-25

import { getInputChangeAction, getAddItemAction, getDeleteItemAction } from ‘./store/actionCreators5.8’  5.8你这个是不是写错了

0
3
qq_慕工程2524350
解决了,Dell老师,谢谢
2020-02-27
共3条回复

React零基础入门到实战,完成企业级项目简书网站开发

主流新技术 React-redux,React-router4,贯穿基础语法

5275 学习 · 2497 问题

查看课程