Skip to content

Commit

Permalink
Update MarkdownTextInput.web.tsx
Browse files Browse the repository at this point in the history
close #166
  • Loading branch information
nandorojo authored Feb 8, 2024
1 parent 348fcd2 commit 64b5c9c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 =
Expand Down Expand Up @@ -449,7 +451,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
divRef.current = r;
};

useEffect(() => {
useClientEffect(() => {
if (!divRef.current || processedValue === divRef.current.innerText) {
return;
}
Expand All @@ -464,7 +466,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
updateTextColor(divRef.current, value);
}, [multiline, processedMarkdownStyle, processedValue]);

useEffect(() => {
useClientEffect(function adjustHeightt() {
if (!divRef.current || !multiline) {
return;
}
Expand Down

0 comments on commit 64b5c9c

Please sign in to comment.