M
M
Maxim Korolsky2016-12-23 20:42:11
JavaScript
Maxim Korolsky, 2016-12-23 20:42:11

How to replace character in string with html tag and draw it all in jsx?

How to replace a character in a string with an html tag and draw it all in jsx
Tried everything for example

{time.replace(String.fromCharCode(183), "<span className='dot'>·</span>")}\
{time.replace(/·/g, <span className='dot'>·</span>)}
{time.replace(/&middot;/g, \<span className='dot'\>·\<\/span\>)}

As well as combinations of these solutions

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aves, 2016-12-23
@SuperPosan

The principle is something like this - split the string into an array, replace the desired one with jsx:

{
  new Date()
    .toLocaleTimeString()
    .match(/[^:]+|:/g)
    .map((e, i) => e == ':' ? <span key={i}>:</span> : e)
}

Example on JSBin

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question