Skip to content

Commit

Permalink
Fix(web-react): Replace useLayoutEffect with useIsomorphicLayoutEffect
Browse files Browse the repository at this point in the history
  * to avoid error messages while rendering on the server side
  • Loading branch information
literat committed Nov 8, 2023
1 parent 563b7fb commit ea9f333
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RefObject, useLayoutEffect } from 'react';
import { RefObject } from 'react';
import { useIsomorphicLayoutEffect } from '../../hooks';
import { FileMetadata } from '../../types/fileUploader';
import { getAttachmentInput, getAttachmentMetaInput } from './utils';

Expand All @@ -17,7 +18,7 @@ export const useFileUploaderAttachment = ({
meta,
onError,
}: UseFileUploaderAttachmentProps) => {
useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
const createAttachmentInput = (metadata: FileMetadata) => {
attachmentRef.current?.querySelectorAll('input').forEach((element) => element.remove());
const attachmentInputElement = getAttachmentInput(file, name, onError);
Expand Down
5 changes: 3 additions & 2 deletions packages/web-react/src/hooks/useClickOutside.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useLayoutEffect, useCallback, MutableRefObject } from 'react';
import { MutableRefObject, useCallback } from 'react';
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';

export interface UseClickOutsideProps {
ref: MutableRefObject<HTMLElement | null>;
Expand Down Expand Up @@ -34,7 +35,7 @@ export const useClickOutside = ({ ref, callback }: UseClickOutsideProps): void =
[ref, callback],
);

useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
document.addEventListener('click', clickHandler, { capture: true });

return () => document.removeEventListener('click', clickHandler, { capture: true });
Expand Down

0 comments on commit ea9f333

Please sign in to comment.