react-string | react replace string
AsimplewaytosafelydostringreplacementwithReactcomponentsAkaturnastringintoanarrayofReactcomponentsInstall$npminstall--savereact-string-replaceUsageSimpleExampleconst reactStringReplace = require(react-string-replace)reactStringReplace(whats your name, your, (match, i) => ( {match}));MorerealisticexampleHighlightalldigitswithinastringbysurroundingtheminspantags:reactStringReplace(Apt 111, phone number 5555555555., /(d+)/g, (match, i) => (
A simple way to safely do string replacement with React components Aka turn a string into an array of React components const reactStringReplace = require(react-string-replace) reactStringReplace(whats your name, your, (match, i) => ( <span>{match}</span> )); Highlight all digits within a string by surrounding them in span tags: reactStringReplace(Apt 111, phone number 5555555555., /(d+)/g, (match, i) => ( <span key={i} style={{ color: red }}>{match}</span> )); const reactStringReplace = require(react-string-replace); const HighlightNumbers = React.createClass({ render() { const content = Hey my number is 555-555-5555.; return ( <div> {reactStringReplace(content, /(d+)/g, (match, i) ...