In my scenario, I want the custom component(AntVX6Comp) fill the parent component.
https://codesandbox.io/s/14m7hi
but I cannot fill up the parent in my component:
my requirement is fill the parent component(or div container) don’t use special number, because the container size will change.
in the Graph API, I only can give specific number as params:
const graph = new Graph({
container: containerRef.current || undefined,
width: 200,
height: 200,
grid: true,
async: true,
background: {
color: "#F2F7FA",
},
});
it cannot use like 100%
to do with it. only number and undefined type, I also tried to use undefined
, but not luck.
so how to let it fill up the parent component in React?
2
Answers
if you can’t use 100% value for the width and height, I suggest calculating the width and height of the parent container using javascript and set the values dynamically on the container element
You can set the dimensions to the parent’s dimensions by getting the
scrollHeight
/clientHeight
andscrollWidth
/clientWidth
from thecontainerRef
.The
||
part is for a default length.