Skip to content

Commit

Permalink
Incubator.Dialog - Fixed content component being created on every ren…
Browse files Browse the repository at this point in the history
…der. (#3231)

* fixed DialogContent component being created on every render and casuing mounts and unmounts

* rename variable
  • Loading branch information
nitzanyiz committed Aug 26, 2024
1 parent 7a890f4 commit e455eb4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/incubator/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const Dialog = (props: DialogProps, ref: ForwardedRef<DialogImperativeMethods>)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const {DialogContent, containerProps, containerStyle} = useDialogContent({
const {renderDialogContent, containerProps, containerStyle} = useDialogContent({
showCloseButton,
close,
closeButtonProps,
Expand Down Expand Up @@ -215,7 +215,7 @@ const Dialog = (props: DialogProps, ref: ForwardedRef<DialogImperativeMethods>)
<GestureDetector gesture={panGesture}>
{/* @ts-expect-error should be fixed in version 3.5 (https://github.com/software-mansion/react-native-reanimated/pull/4881) */}
<View {...containerProps} reanimated style={style} onLayout={onLayout} ref={setRef} testID={testID}>
<DialogContent/>
{renderDialogContent()}
</View>
</GestureDetector>
);
Expand Down
4 changes: 2 additions & 2 deletions src/incubator/Dialog/useDialogContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const useDialogContent = (props: InternalDialogCloseButtonProps) => {
return showCloseButton ? [propsContainerStyle, styles.transparent] : propsContainerStyle;
}, [showCloseButton, propsContainerStyle]);

const DialogContent = () => {
const renderDialogContent = () => {
const DialogContent = (
<>
{headerProps && <DialogHeader {...headerProps}/>}
Expand All @@ -69,7 +69,7 @@ const useDialogContent = (props: InternalDialogCloseButtonProps) => {
}
};

return {DialogContent, containerStyle, containerProps};
return {renderDialogContent, containerStyle, containerProps};
};

export default useDialogContent;
Expand Down

0 comments on commit e455eb4

Please sign in to comment.