Replace part of string with tag in JSX

前端 未结 12 1240
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 09:39

I\'m trying to replace parts of a string with JSX tags, like so:

render: function() {
    result = this.props.text.replace(\":\",
12条回答
  •  攒了一身酷
    2020-12-16 10:21

    After some research I found that existing libraries doesn't fit my requirements. So, of course, I have written my own:

    https://github.com/EfogDev/react-process-string

    It is very easy to use. Your case example:

    let result = processString({
        regex: /:/gim,
        fn: () => 
    })(this.props.test);

提交回复
热议问题