Pass ref in routeData
Happy Saturday. Struggling with what I hope is a simple problem.
I'm trying to get a ref passed to a grand child component. It keeps showing up as undefined. Ref works fine in the grand parents where it's set to a div.
In the grand parent:
let ref
export function routeData() {
return ref
}
In the grand child:
const test = useRouteData()
createEffect(() => {
console.log('test is: ', test)
})`
I know the ref eventually gets a value so not sure why it's only showing up as undefined in the grand child6 Replies
You probably want to use a context for this instead of routeData
I would also suggest using a signal for the ref rather than the variable way
OK I kind of tried that too and didn't have much luck.... I kept getting "fn is not a function". I'll try using a signal for the ref
beautiful. thanks for getting me through that
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Does anyone have a code example for this?
sure one sec
This is the context provider I made for refs:
import { createContext, createSignal, useContext } from 'solid-js'
Then you can import like this:
const setNewParas = createNewSetParas()
an set the refs using that function........ if that makes sense
maybe it makes no sense
Set refs like this: setNewParas((p) => [...p, el])
or setBookRefs(() => el)
I figured out how to do it, thanks.