In React, replace a character in a string with a component, and then render it. How do you replace it?

for example, there is a string such as abcd {1} efadf,

is there a way to replace {1} with a component, and then render the result after replacement?

Thank you!

Feb.08,2022

wrote a demo
https://codepen.io/mugou/pen/.


you can do this by dividing the string into arrays, replacing the corresponding with components of React, and then rendering:


      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>
      <div>{segs}</div>
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3bde1-2c2bf.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3bde1-2c2bf.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?