I need to render a React child component from UV coordinates (normalized coordinates / U & V are typically in [0;1] range)
But I don't know how to get parent dimension during children rendering.
I would like to perform something like (using tsx):
const Child = (props: {u:Number, v:Number}) =>
<circle cx={parentClientWidth*props.u} cy={parentClientHeight*props.v} r="5" fill="black"></circle>;
const Parent = () =>
<svg>
<Child u={0.3} v={0.5} />
</svg>;
I woulder if using a context object could be the right way?...
const Child = (props: {u:Number, v:Number}) => {
const workspace= useContext(WorkspaceContext);
return <circle cx={workspace.width*u} cy={workspace.height*v} r="5"></circle>;
}
Note: In this simple case I could use percents for my cx and cy coordinates but my real case is much more complicated...