Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获取组件_Javascript_Reactjs_Typescript_Mobx_Recharts - Fatal编程技术网

Javascript 如何获取组件

Javascript 如何获取组件,javascript,reactjs,typescript,mobx,recharts,Javascript,Reactjs,Typescript,Mobx,Recharts,如何获得“g”和“文本”的宽度,并将其用于后续计算 const CustomizedAxisTick: React.FunctionComponent<ICustomTickProps> = ({x,y,payload,width,fill}) => { const firstLine = 12 const secondLine = 24 const dateTime = payload.value return (

如何获得“g”和“文本”的宽度,并将其用于后续计算

const CustomizedAxisTick: React.FunctionComponent<ICustomTickProps> = ({x,y,payload,width,fill}) => {
        const firstLine = 12
        const secondLine = 24
        const dateTime = payload.value

    return (
        <g transform={`translate(${x},${y})`}>
            <text fontFamily="Roboto, sans-serif" transform={"rotate(-45)"} width={width} height="auto" textAnchor="middle" fontSize={12} fill={fill}>
            </text>
        </g>
    );
}
const CustomizedAxisTick:React.FunctionComponent=({x,y,有效载荷,宽度,填充})=>{
常数firstLine=12
const secondLine=24
const dateTime=payload.value
返回(
);
}
尝试对元素使用“ref”:


从ref可以得到clientHeight/offsetHeight和clientWidth/offsetWidth。

即使它们是CustomizedExistick的一部分,也可以同时得到它们吗?ref将保存DOM元素。所以,只要这个元素有高度和宽度,它就应该适合你。好的,谢谢!