Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Replace text in array of strings and react-components

i would like to replace some text with component in array that contains strings and react components. In the code snipet below, i see that the nodes were modified, but after foreach loop no changes are detected in array. Why? What goes wrong?

import parser from 'react-html-parser';

const text = 'i am a string (item) with <ul><li>first item</li><li>second item</li></ul> and some text';

// create array of strings and react components 
const arrNodes = parser(text);

// loop and replace
arrNodes.forEach(function iter(node){
 if(typeof node === 'string') {
   if(node.indexOf('item') > -1) {
     const newNode = node.split('item'); 
     newNode.splice(1,0, 'Component'); // later should be react component
     node = newNode;
   }
  }
 if(node.props && node.props.children && Array.isArray(node.props.children)) {
    node.props.children.forEach(iter);
 }
})
console.log(arrNodes)
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!