From 64b5c9c552372f57123d1f5f0130c1010e724a4c Mon Sep 17 00:00:00 2001 From: Fernando Rojo Date: Thu, 8 Feb 2024 10:33:35 -0500 Subject: [PATCH] Update MarkdownTextInput.web.tsx close #166 --- src/MarkdownTextInput.web.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/MarkdownTextInput.web.tsx b/src/MarkdownTextInput.web.tsx index f3f80823..0f1a9980 100644 --- a/src/MarkdownTextInput.web.tsx +++ b/src/MarkdownTextInput.web.tsx @@ -9,7 +9,7 @@ import type { TextInputKeyPressEventData, TextInputFocusEventData, } from 'react-native'; -import React, {useEffect, useRef, useCallback, useMemo} from 'react'; +import React, {useEffect, useRef, useCallback, useMemo,useLayoutEffect} from 'react'; import type {CSSProperties, MutableRefObject, ReactEventHandler, FocusEventHandler, MouseEvent, KeyboardEvent, SyntheticEvent} from 'react'; import {StyleSheet} from 'react-native'; import * as ParseUtils from './web/parserUtils'; @@ -21,6 +21,8 @@ import InputHistory from './web/InputHistory'; require('../parser/react-native-live-markdown-parser.js'); +const useClientEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect; + let createReactDOMStyle: (style: any) => any; try { createReactDOMStyle = @@ -449,7 +451,7 @@ const MarkdownTextInput = React.forwardRef( divRef.current = r; }; - useEffect(() => { + useClientEffect(() => { if (!divRef.current || processedValue === divRef.current.innerText) { return; } @@ -464,7 +466,7 @@ const MarkdownTextInput = React.forwardRef( updateTextColor(divRef.current, value); }, [multiline, processedMarkdownStyle, processedValue]); - useEffect(() => { + useClientEffect(function adjustHeightt() { if (!divRef.current || !multiline) { return; }