Library provides native method for replacing selected text in TextInput with a new text
npm install -S react-native-replace-selectedyarn add react-native-replace-selectedimport{replaceSelected}from'react-native-replace-selected';replaceSelected(textInputRef.current,"new text");importReact,{useState,useRef}from'react';import{StyleSheet,View,Button,TextInput}from'react-native';import{useReplaceSelected}from'react-native-replace-selected';exportdefaultfunctionApp(){const[text,setText]=useState('Example Text');consttextInputRef=useRef<TextInput>(null);constreplaceSelected=useReplaceSelected(textInputRef);constreplaceText=()=>replaceSelected('😀');return(<View><TextInputref={textInputRef}onChangeText={setText}value={text}/><Buttontitle="Replace selected text with 😀"onPress={replaceText}/></View>);}importReact,{useState,useRef}from'react';import{StyleSheet,View,Button,TextInput}from'react-native';import{replaceSelected}from'react-native-replace-selected';exportdefaultfunctionApp(){const[text,setText]=useState('Example Text');consttextInputRef=useRef<TextInput>(null);constreplaceText=()=>{if(!textInputRef.current)return;replaceSelected(textInputRef.current,'😀');};return(<View><TextInputref={textInputRef}onChangeText={setText}value={text}/><Buttontitle="Replace selected text with 😀"onPress={replaceText}/></View>);}See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library