P
P
Pavel Didenko2019-07-03 18:00:18
React
Pavel Didenko, 2019-07-03 18:00:18

Is it safe to use dangerousSetInnerHTML in this case?

I implement a sadgest like a Yandex sadgest. I need to highlight matching results in sadgest based on the value of the input. In general, in fact, as in the Yandex search bar.
Yandex highlighting comes from tags . Our search on the back is elastic, and the back can send me data in the same form with , but I can only insert them as HTML through dangerouslySetInnerHTML do I get renders from the backend, not from user input? And if this implementation is not the best option, then how to do it better? Regulars? <b><b>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-07-03
@rockon404

If you are sure that only text with tags will come to you <b>, then there is no danger.
The property has the word dangerously in its name so that programmers remember that this is a potentially dangerous action, and not because any use of it is dangerous and not desirable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question