-
Notifications
You must be signed in to change notification settings - Fork 21
Closed
Description
When using useRef to get the current element I get always get an empty object when referencing from a React Wrapper element.
I encountered this on a project I’m working on and could replicate it with the react-wrapper demo in the cem-tools repo.
I adapted the App.tsx file to reproduce the bug. Or, what I think is a bug. Could it be a timing issue?
demo/react-app/src/App.tsx
import { useState, useRef, useEffect } from "react";
import "./App.css";
import { MyButton } from "lit-app/dist/react";
function App() {
const [count, setCount] = useState(0);
const myButtonRef = useRef(null); // <-- initialValue is null
const counter = () => {
console.log(myButtonRef.current); // <-- logs `{}`
setCount((count) => count + 1);
}
useEffect(() => {
console.log(myButtonRef.current); // <-- logs `{}`
},[]);
return (<MyButton ref={myButtonRef} onClick={counter}>
count is {count}
</MyButton>);
}
export default App;Note: Replacing <MyButton> with <my-button> makes the issue go away and ref={myButtonRef} returns the Custom Element.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels