react-native-replace-selected
v1.1.0
Published
This library provides native method for replacing selected text in react-native's TextInput with a new text
Downloads
10
Readme
react-native-replace-selected
Library provides native method for replacing selected text in TextInput with a new text
Installation
npm install -S react-native-replace-selected
yarn add react-native-replace-selected
Usage
import { replaceSelected } from 'react-native-replace-selected';
replaceSelected(textInputRef.current, "new text");
import React, { useState, useRef } from 'react';
import { StyleSheet, View, Button, TextInput } from 'react-native';
import { useReplaceSelected } from 'react-native-replace-selected';
export default function App() {
const [text, setText] = useState('Example Text');
const textInputRef = useRef<TextInput>(null);
const replaceSelected = useReplaceSelected(textInputRef);
const replaceText = () => replaceSelected('😀');
return (
<View>
<TextInput ref={textInputRef} onChangeText={setText} value={text} />
<Button title="Replace selected text with 😀" onPress={replaceText} />
</View>
);
}
import React, { useState, useRef } from 'react';
import { StyleSheet, View, Button, TextInput } from 'react-native';
import { replaceSelected } from 'react-native-replace-selected';
export default function App() {
const [text, setText] = useState('Example Text');
const textInputRef = useRef<TextInput>(null);
const replaceText = () => {
if (!textInputRef.current) return;
replaceSelected(textInputRef.current, '😀');
};
return (
<View>
<TextInput ref={textInputRef} onChangeText={setText} value={text} />
<Button title="Replace selected text with 😀" onPress={replaceText} />
</View>
);
}
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library