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

120
Views
Replace Text node with React Element via react-native-render-html in React Native

Problem

I am using react-native-render-html to render some html in React Native. The problem is that this html contains some placeholders like {{{placeholder:items:0}}} which should be replaced with a React Element.

Code

I am using the onText function currently as outlined in this example:

  function onText(text) {
    const toReplace = text.data.match(gemstoneRegex);

    if (toReplace?.length) {
      let [placeholder] = toReplace;
      placeholder = placeholder.replace(/\{/g, "");
      placeholder = placeholder.replace(/\}/g, "");

      const [name, position] = placeholder.split(":items:");

      text.data =
        (
          <Gemstone
            stones={[gemstones[name]?.de[position]]}
            displayTitle={gemstones[name]?.de[0]?.displaytitle || name}
            fieldName={name}
          />
        ) || `${name} couldn't be replaced!`;
    }
  }

This would work fine for a simple text string, but unfortunately not for a React Element. Is there a way to do this? The onElement function seems to have utility methods to add and remove elements. Is that also possible for text nodes?

almost 4 years ago · Santiago Trujillo
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!