{"repo":"iansinnott/react-string-replace","free":true,"listed":false,"github":"https://github.com/iansinnott/react-string-replace","clone":"git clone https://github.com/iansinnott/react-string-replace.git","description":"A simple way to safely do string replacement with React components","language":"JavaScript","stars":666,"topics":["react","string-manipulation","react-components"],"license":"MIT","category":"ui-components","readme_excerpt":"React String Replace A simple way to safely do string replacement with React components. Zero dependencies. Aka turn a string into an array of React components Install Usage First, import the lib. Both require and import are supported. Examples will use import since it is more common in the React ecosystem. Simple Example More realistic example Highlight all digits within a string by surrounding them in span tags: Within a React component Multiple replacements on a single string You can run multiple replacements on one string by calling the function multiple times on the returned result. For instance, if we want to match URLs, @-mentions and hashtags in a string we could do the following: Full Example See the example/ directory for a runnable example. Why? I wanted an easy way to do string replacement similar to String.prototype.replace within React components without breaking React's built in string escaping and XSS protection. This meant standard string replacement combined with dangerouslySetInnerHTML was out of the question. API reactStringReplace(string, match, replacementFunction, count) string Type: string array The string or array you would like to do replacement on. NOTE: When passed an array this is the same as running the replacement on every string within the array. Any non-string values in the array will be left untouched. match Type: regexp string The string or RegExp you would like to replace within string . NOTE: When using a RegExp you MUST include a capturin","default_branch":null,"files":null,"tree":[],"storefront":"/r/iansinnott","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/iansinnott/react-string-replace/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}