Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move height to layout effect #166

Closed
nandorojo opened this issue Feb 8, 2024 · 5 comments · Fixed by #169
Closed

Move height to layout effect #166

nandorojo opened this issue Feb 8, 2024 · 5 comments · Fixed by #169

Comments

@nandorojo
Copy link
Contributor

useEffect(() => {
if (!divRef.current || !multiline) {
return;
}
const elementHeight = getElementHeight(divRef.current, inputStyles, numberOfLines);
divRef.current.style.height = elementHeight;
divRef.current.style.maxHeight = elementHeight;
}, [numberOfLines]);

Hey! Reviewing the web code, and I'm wondering if this should get moved to a layout effect since it's adjusting the height and you'd want to do this before painting. I'm happy to PR it if so!

@nandorojo
Copy link
Contributor Author

The same would go for this effect:

useEffect(() => {
if (!divRef.current || processedValue === divRef.current.innerText) {
return;
}
if (value === undefined) {
parseText(divRef.current, divRef.current.innerText, processedMarkdownStyle);
return;
}
const text = processedValue !== undefined ? processedValue : '';
parseText(divRef.current, text, processedMarkdownStyle, text.length);
updateTextColor(divRef.current, value);
}, [multiline, processedMarkdownStyle, processedValue]);

I can test them out a bit to be certain

@tomekzaw
Copy link
Collaborator

tomekzaw commented Feb 8, 2024

@nandorojo Thanks for reviewing the code and suggesting the improvements, feel free to submit PRs!

cc @Skalakid, the author of web implementation

@nandorojo
Copy link
Contributor Author

Cool.

Making a small note for SSR support:

const useClientEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect

@tomekzaw
Copy link
Collaborator

tomekzaw commented Feb 8, 2024

FYI There's a PR that eliminates .web.tsx file extension in favor of .native.tsx (#168). Let's get it merged first so we can avoid conflicts.

@nandorojo
Copy link
Contributor Author

nandorojo commented Feb 8, 2024

Sounds good.

Also, PR opened #169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants