I know that I could use Context or props, but I want to see if there is something more generic or simpler to detect if I have my component standalone (let's say directly in a form) or if I have it inside a table.
In React JS.
I know that I could use Context or props, but I want to see if there is something more generic or simpler to detect if I have my component standalone (let's say directly in a form) or if I have it inside a table.
In React JS.
In order to check if your current element is a descendant of some other element you can walk up the DOM starting with the element in question with Node.parentElement() (docs) and check whether that element has the attributes you're looking for (e.g in your case nodeName TABLE (docs)).
In order to get a handle on your react element, you can use a ref (docs)