How can i use a ref to my html dom element into the store? #1833
Unanswered
NirmalRaj-byjus
asked this question in
Q&A
Replies: 2 comments 13 replies
-
@NirmalRaj-byjus would you mind sharing us a basic example of your implementation on codesandbox? |
Beta Was this translation helpful? Give feedback.
10 replies
-
Here is what worked for me, using ref callbacks: In my zustand store: settingsContainerRef: createRef() as MutableRefObject<HTMLDivElement>,
setSettingsContainerEl: (element: HTMLDivElement | null) => {
if (!element) {
return;
}
const newRef = createRef() as MutableRefObject<HTMLDivElement>;
newRef.current = element;
set({ settingsContainerRef: newRef });
}, In my jsx: <div
ref={setSettingsContainerEl} hope that helps 🙏 |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In my store,'Remotestream' is a key value pair as below type,
type RemoteStream = {
uid: string;
isVideoEnabled: boolean;
isAudioEnabled: boolean;
name: string;
streamRef: Ref<HTMLDivElement | null> | null;
isVisible: boolean;
isBlocked: boolean;
isPinned: boolean;
isFocused: boolean;
isHandRaised: boolean;
isNew: boolean;
};
In this object, streamRef is a prop contains ref to the div element, so during rendering i need this ref to be attached to the target div element.
But I'm facing below error.
How can i use this.. or whats the effective way of implementing it.
Beta Was this translation helpful? Give feedback.
All reactions