import PropTypes from 'prop-types'; 引入PropTypes之后 为什么编译失败了?
来源:4-2 PropTypes 与 DefaultProps 的应用
慕莱坞2689431
2020-11-14
Failed to compile
./src/JS/Items.js
SyntaxError: C:\Users\XD\my-app\src\JS\Items.js: Unexpected token (26:13)
24 | }
25 |
26 | Items.propTypes = {
| ^
27 | content: PropTypes.string,
28 | index: PropTypes.number,
29 | handleItemDelete: PropTypes.func
2回答
-
慕莱坞2689431
提问者
2020-11-14
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class Items extends Component {
constructor(props) {
super(props);
this.handClick = this.handClick.bind(this)
}
render() {
const { content } = this.props;
return <div onClick={this.handClick}>
{content}
</div>
}
handClick() {
const { index, handleItemDelete } = this.props;
handleItemDelete(index);
}
Items.propTypes = {
content: PropTypes.arrayOf(PropTypes.string, PropTypes.number),
index: PropTypes.number.isRequired,
handleItemDelete: PropTypes.func
}
}
022020-11-18 -
Dell
2020-11-14
你代码贴上来我看看大,语法感觉写的有问题
00
相似问题