Replace part of string with tag in JSX

前端 未结 12 1264
被撕碎了的回忆
被撕碎了的回忆 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:13

    Nothing around WEB globe worked for me exept this solution - https://www.npmjs.com/package/regexify-string

    Working with React, strings and doesn't have any additional dependecies

    regexifyString({
        pattern: /\[.*?\]/gim,
        decorator: (match, index) => {
            return (
                
                    {match}
                
            );
        },
        input: 'Some text with [link]',
    });
    

提交回复
热议问题