0
<Hello name={'\u4ed8\u52a0\u4fa1\u5024\u7a0e# IE9834481A'}></Hello>
class Hello extends Component {
    render() {
        return (
            <div>
                {this.props.name}
            </div>
        );
    }
}

The above 2 code snippets are working fine & giving the result as expected, i.e, the escape sequences are getting converted to the relevant unicode characters.

Now consider, there is an array(dynamically populated) and the array values will be the default value for the input tag & this array contains unicode escape sequences.

Ex: <input value={array[i]}></input>

I have tried doing <input value={<Hello name={array[i]}></Hello>}></input>

But the o/p is [object Object].

If I hardcode the string in input tag, o/p is as expected <input value={<Hello name={'\u4ed8\u52a0\u4fa1\u5024\u7a0e'}></Hello>}></input>

How should I solve this issue, ultimately I want to pre-populate input tag with array value containing unicode escape sequences (after converting to unicode characters).

Anjali
  • 143
  • 1
  • 6
  • Does this answer your question? [How do I decode a string with escaped unicode?](https://stackoverflow.com/questions/7885096/how-do-i-decode-a-string-with-escaped-unicode) – Drew Reese Jan 08 '20 at 07:34
  • Put your code on codesandbox. I can't see how what you last put would even work since jsx is being put into a value field (shouldn't work). – SILENT Jan 08 '20 at 08:12

2 Answers2

0

console.log(JSON.parse('"\u4ed8\u52a0\u4fa1\u5024\u7a0e# IE9834481A"'));
Drew Reese
  • 165,259
  • 14
  • 153
  • 181
0

It is not allowed to pass a React Node to the input value. Here is a string expected. If you need the Hi use a function.

const hello = (name) => `Hi ${name}`;


ReactDOM.render(
  <input value={hello('\u4ed8\u52a0\u4fa1\u5024\u7a0e')}></input>,
  document.getElementById('root')
);
Flui
  • 146
  • 6
  • Hi Flui, "Hi" can be removed, The point is I want nicode characters (from unicode escape sequences u). – Anjali Jan 08 '20 at 08:37
  • in this case https://stackoverflow.com/questions/7885096/how-do-i-decode-a-string-with-escaped-unicode – Flui Jan 08 '20 at 13:30