Fix Prop dangerouslySetInnerHTML did not match

Felix Lee
Jun 26, 2021

--

Photo by Joan Gamell on Unsplash

Came across this warning when using dangerouslySetInnerHTML on ReactJS.

Warning: Prop `dangerouslySetInnerHTML` did not match. Server...

Here is the snippet that causes the problem:

Notice how I set input holding the <p> tag value as string, to a <p> tag on the JSX.

The fix is simple, just change the <p> tag on the JSX to a <div> , like so

Not only it fixes the warning, it also more semantically correct on HTML.

--

--

Felix Lee
Felix Lee

Written by Felix Lee

Software engineer in Singapore. Write random tech stuff. Still figuring out this “life” thing in life.

Responses (2)