Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use bind in render() #17

Merged
merged 3 commits into from Jul 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Expand Up @@ -98,6 +98,12 @@ Then in JSX:

```js
class MyComponent extends React.Component {

constructor(props, context) {
super(props, context);
this.onCreditCardChange = this.onCreditCardChange.bind(this);
}

onCreditCardChange(event) {
// formatted pretty value
console.log(event.target.value);
Expand All @@ -110,7 +116,7 @@ class MyComponent extends React.Component {
return (
<Cleave placeholder="Enter your credit card number"
options={{creditCard: true}}
onChange={this.onCreditCardChange.bind(this)} />
onChange={this.onCreditCardChange} />
);
}
}
Expand Down
10 changes: 7 additions & 3 deletions doc/reactjs-component-usage.md
Expand Up @@ -50,6 +50,10 @@ class MyComponent extends React.Component {
phoneRawValue: '',
customRawValue: ''
};

this.onCreditCardChange = this.onCreditCardChange.bind(this);
this.onPhoneChange = this.onPhoneChange.bind(this);
this.onCustomChange = this.onCustomChange.bind(this);
}

onCreditCardChange(event) {
Expand All @@ -68,13 +72,13 @@ class MyComponent extends React.Component {
return (
<div>
<Cleave placeholder="Enter your credit card number" options={{creditCard: true}}
onChange={this.onCreditCardChange.bind(this)}/>
onChange={this.onCreditCardChange}/>

<Cleave className="css-phone" options={{phone: true, phoneRegionCode: 'AU'}}
onChange={this.onPhoneChange.bind(this)}/>
onChange={this.onPhoneChange}/>

<Cleave options={{blocks: [4,3,3], delimiter: '-', numericOnly: true}}
onChange={this.onCustomChange.bind(this)}/>
onChange={this.onCustomChange}/>

<div>
<p>credit card: {this.state.creditCardRawValue}</p>
Expand Down