diff --git a/README.md b/README.md index 6ce343e..e0d0472 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,11 @@ export default class Container extends Component { return ( this.setState({ value: value.replace(/\D/g, '') })} + onChangeText={(value) => { + const newValue = value.replace(/\D/g, ''); + this.setState({ value: newValue }); + return newValue; // must return a value + } value={this.state.value} style={{ width: 300, height: 70, borderWidth: 1 }} /> diff --git a/index.js b/index.js index 541956e..34cd65d 100644 --- a/index.js +++ b/index.js @@ -91,7 +91,9 @@ export class ControlledInput extends PureComponent { const nextSelection = this.getNextSelection(value, nextValue, selection); this.setState({ selection: nextSelection }); if (onChangeText) { - onChangeText(nextValue); + const _nextValue = onChangeText(nextValue); + const _nextSelection = this.getNextSelection(nextValue, _nextValue, nextSelection); + this.setState({selection: _nextSelection}); } return this.props.onKeyPress && this.props.onKeyPress(event); }