score:0

Accepted answer

you need to assert the ref, use ref as mutablerefobject<htmldivelement> as it is not necessary for every ref to have the current property.

in your parent component, use (ref as mutablerefobject<htmldivelement>).current

score:0

you can't access the the dom node until it is mounted. use useeffect hook to check after mount.

const child = react.forwardref<htmldivelement | null, iprops>(
    (props, ref) => {

        useeffect(()=>{
          console.log(ref.current)
      },[])
      
      return <div ref={ref}>hello world</div>;
    }
  );

Related Query

More Query from same tag