How to access the `<svg>` Element in `UseEffect()` in React?

Viewed 169

I have a React website in which I display a React-Icon:

import { BsHouse } from 'react-icons/bs';

It gets rendered as a SVG which I can access in the Firefox Developer Tools: enter image description here

But when I try to access it in UseEffect() on my React page, it is null:

const path = document.getElementsByTagName('body')[0]; // null

Although I can access other tags such as body, div, a etc.

It appears that the <svg> and <path> elements haven't been rendered at this point.

Where and when can I access <path> in my React page after they are rendered in DOM?

0 Answers
Related