Skip to content

Commit

Permalink
Bump npm package version to v2.0.0 and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Suzii committed Jul 4, 2017
1 parent e55d361 commit d8ad590
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# react-set-state-usage [![CircleCI](https://circleci.com/gh/sutrkiller/react-set-state-usage.svg?style=shield&svg)](https://circleci.com/gh/sutrkiller/react-set-state-usage) [![npm version](https://img.shields.io/npm/v/react-set-state-usage.svg?style=flat)](https://www.npmjs.com/package/react-set-state-usage) ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)

**react-set-state-usage** is a rule, that enforces usage of callbacks in setState calls instead of objects.
**react-set-state-usage** is a rule, that enforces usage of callbacks in setState calls instead of objects. Moreover, it forbids access to `this.props` and `this.state` within `setState(...)` calls.

* **updater-only:** it also has updater-only option to forbid usage of second `callback` parameter of setState

Expand Down Expand Up @@ -34,7 +34,7 @@ To enable the **updater-only** option, rule should be used like this:
## Examples

```tsx
class NameDemo extends React.Component<{ someCallback: () => void }, { name: string }> {
class NameDemo extends React.Component<{ someFlag: boolean, someCallback: () => void }, { redundandFlag: boolean, name: string }> {

constructor(props) {
super(props);
Expand All @@ -48,10 +48,12 @@ class NameDemo extends React.Component<{ someCallback: () => void }, { name: str

function onBadClick() {
this.setState({ name: 'badName' }); // will produce tslint error
this.setState({ redundandFlag: this.props.flag }); // will produce tslint error, same holds for 'this.state' access
}

function onGoodClick() {
this.setState(() => ({ name: 'goodName' })); // will not produce tslint error
this.setState((state, props) => ({ redundandFlag: props.flag })); // will not produce tslint error
}

function onSomeOtherClick() {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-set-state-usage",
"version": "1.0.4",
"version": "2.0.0",
"description": "TSLint rule for detection non-functional setState statements",
"main": "tslint.json",
"scripts": {
Expand Down

0 comments on commit d8ad590

Please sign in to comment.