Created
July 24, 2021 18:40
-
-
Save gdibble/2edc1ccbe6340f887b4ba3907e26cabc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** replaceJSX | |
* RegExp search text and replace with JSX | |
* @see https://stackoverflow.com/a/63647844 | |
* @param {string} str | |
* @param {RegExp} find | |
* @param {JSX} replace | |
* @returns {JSX} | |
*/ | |
export default function replaceJSX(str, find, replace) { | |
const parts = str.split(find); | |
const result = []; | |
for (let i = 0; i < parts.length; i++) { | |
result.push(parts[i]); | |
if (i < parts.length - 1) result.push(replace); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try:
https://codesandbox.io/s/hardcore-fast-8dzxk?file=/src/index.js