You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My case is that I have a base map in svg format, this base map can be changed by user and loaded from server, once the map is loaded I need to get the svg's bbox to have width and height of the component. I've thought this may be implmented with using ref and passing down to the base map component from parent, and using the ref.getBBox(). But the onMount function in parent component doesn't seems to get the ref at the time of child being mounted.
parent component:
function App() {
let svgRef
onMount(()=> {
console.log(svgRef) /* always undefined */
})
return <DynaSvg name="basemap" ref={svgRef} />
}
the dynamically created asynic child component:
import { createResource } from "solid-js";
export const DynaSvg = (props) => {
const fetchSvg = async ({ name, parentRef }) => {
/* the passed ref is being assigned with a value now */
let componentObject = (await import(/* @vite-ignore */ `./${name}.svg`))
.default;
componentObject.ref = parentRef;
return componentObject;
};
const [SvgComp] = createResource(
{ name: props.name, parentRef: props.ref },
fetchSvg,
);
return (
<>
<span> {SvgComp.loading && "loading..."} </span>
{SvgComp()}
</>
);
};
Now my question is, is there a way to grab the forwared ref in a asynic created component? Or just using store/signal to get the child dimensions?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
My case is that I have a base map in svg format, this base map can be changed by user and loaded from server, once the map is loaded I need to get the svg's bbox to have width and height of the component. I've thought this may be implmented with using ref and passing down to the base map component from parent, and using the
ref.getBBox()
. But theonMount
function in parent component doesn't seems to get the ref at the time of child being mounted.parent component:
the dynamically created asynic child component:
Now my question is, is there a way to grab the forwared ref in a asynic created component? Or just using store/signal to get the child dimensions?
Beta Was this translation helpful? Give feedback.
All reactions