未在React中定义变量

时间:2019-07-11 18:30:23

标签: javascript reactjs eslint

我在React上有这个错误: ./src/App.js Line 44: 'newQuantityById' is not defined no-undef Line 45: 'newQuantityById' is not defined no-undef

这是关于函数中的代码的,而newQuantityById是const

`removeFromCart = (id) => {
    const {addedIds,quantityById} = this.state;
    if(quantityById[id]){
      const newQuantitById = {
        ...quantityById,
        [id]: quantityById[id] > 1 ? quantityById[id] - 1 : undefined
      }
      const newAddedIds = newQuantityById[id] ? addedIds : addedIds.filter(prodId => prodId !== id); //Line 44 Error
      this.setState({addedIds: newAddedIds, quantityById: newQuantityById}); //Line 45 Error
    }
  }`

1 个答案:

答案 0 :(得分:4)

您在这里有错字:

Container(
    width: MediaQuery.of(context).size.width / 2
    child: Text(
      "Hello world!!!!",
      maxLines: 2,
      overflow: TextOverflow.ellipsis
    ),
);

您错过了const newQuantitById = { ^^

相关问题