Help with Forward Ref and Ref from solid-primatives
I am still pretty new to solidjs and typescipt in general, i am trying to port a library from react to solid and am 90% of the way there - however i am having difficulties with using a forward Ref.
There are two sections that are confusing me - that i would like help trying to solve.
Chart.tsxAnd
typedCharts.tsxI am not exactly sure how to solve the
forwardRef
situation here.4 Replies
there is no need to use forwardref hoc at all
just call props.ref() with the ref you want to pass to the parent
in solid-primitives there is
mergeRefs
which can make the types easier but all it's doing is calling props.refyes - i know, the above snippets are from the react code.
yeah - this part is what's confusing me - i've tried. I just get a bunch of errors.
Obviously i am missing something 😅
mergeRefs
worked very well. I refactored to use an interface and i got it working 🙂
My issue was i wasn't using an interface to pass the props, so the componnet couldn't see the ref
attribute.not sure what that means, but I'm glad it's working
I think the only important part of refs in solid is:
- props.ref is always a function, even if it's typed as a variable
- make sure to call it before perent's onMount
trying to pass the props as
function Component (props, ref) {}
wasn't working - when i did: function Component (props: {height: number, ...., ref: Ref<ChartJS | null>})
it started to work.