ElemeFE / ElemeFE/element-react

分页组件里有警告错误 :Do not mutate state directly. Use setState() react/no-direct-mutation-state

Open
#735 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.8k
Forks
435
PR merge metrics
No merged PRs in 30d

Description

### Description

pagination分页组件里报警告

这个代码里:https://github.com/eleme/element-react/blob/master/src/pagination/Pager.jsx

我看到了源码中更新状态 是这样的:

this.state.showPrevMore = showPrevMore;
this.state.showNextMore = showNextMore;
this.state.quickprevIconClass = showPrevMore
? this.state.quickprevIconClass
: 'el-icon-more';
this.state.quicknextIconClass = showNextMore
? this.state.quicknextIconClass
: 'el-icon-more';

![image](https://user-images.githubusercontent.com/20555332/37077747-40bf9c5e-2217-11e8-8690-2a0f972fb09a.png)

**能告诉我用this.state这样,而不用setState是有什么特别的吗?**
**能告诉我用this.state这样,而不用setState是有什么特别的吗?**
**能告诉我用this.state这样,而不用setState是有什么特别的吗?**

所以给出警报 :

![image](https://user-images.githubusercontent.com/20555332/37077771-5c1d2ea8-2217-11e8-8c62-1b2af06835f3.png)

https://github.com/eleme/element-react/blob/master/src/date-picker/basic/TimeSpinner.jsx
上面这个datepicker另外我还看到了这样的代码:

function withIndex(arr) {
return arr.map((e, i) => (e, i));
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.