React ref not render on first load
React
Join us for free and unlock more features!
Access all features and save your workâno cost, no hassle.
React
Typescript
index
const editorRef = useRef<TiptapEditorRef>(null);
return (
<TiptapEditor
ref={editorRef}
onFocus={() => setInputActive(true)}
onBlur={() => setInputActive(false)}
onUpdate={handleGetTags}
/>
)null. This mean that ref did not load at all on first render. Just as the react document said useRefreturns a ref object with a singlecurrentproperty initially set to the initial value you provided.
Typescript
index
const [shouldUpdate, setShouldUpdate] = useState(true);
useEffect(() => {
if (shouldUpdate) setShouldUpdate(false);
}, [shouldUpdate]);
useEffect(() => {
{...fetchDataLogic...}
editorRef.current?.editor?.commands.setContent(data?.content);
},[shouldUpdate)