kaiserkais's avatar

React.createelement and useref()

Hi, im trying to use useRef() with React.create element but not working

const scrollref = useRef()

<div className='flex flex-col gap-4'>
    {settings.p_components.map((block) => {
        if (typeof Components[block.component_name] !== "undefined") {
            if (block.component_name == "pchForm") {
                return React.createElement(Components[block.component_name], {
                    key: block.id,
                    product: product,
                    ref:scrollref 
                });
            } 
        }

        );
    }
    )}
</div>
0 likes
4 replies
Sinnbeck's avatar

If we are going to try and help you, please explain the problem. "not working" can mean many things. Let me guess. You h1 tags are pink instead of red?

kaiserkais's avatar

@Sinnbeck im sorry, you are right, im getting this error in console

 Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()
kaiserkais's avatar
kaiserkais
OP
Best Answer
Level 2

I found a solution when i put react createelement inside a div and add ref it works perfectly

Please or to participate in this conversation.