Skip to content

Commit 2323f14

Browse files
authored
Merge pull request #816 from glints-dev/feature/fix-fun-ref-changes-on-renders
chore: wraps open and close functions in useCallback hook
2 parents fc1a051 + 070b484 commit 2323f14

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/@next/Alert/AlertProvider.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import React, { useState } from 'react';
1+
import React, { useCallback, useState } from 'react';
22
import { AlertProps } from './Alert';
33
import { AlertContext, ShowAlertProps } from './AlertContext';
44

55
export const AlertProvider = ({ children }: { children: React.ReactNode }) => {
66
const [state, setState] = useState<AlertProps>({ show: false });
77

8-
const open = (props: ShowAlertProps) => setState({ ...props, show: true });
8+
const open = useCallback(
9+
(props: ShowAlertProps) => setState({ ...props, show: true }),
10+
[setState]
11+
);
912

10-
const close = () => setState({ show: false });
13+
const close = useCallback(() => setState({ show: false }), [setState]);
1114

1215
const alertContextValue = { ...state, open, close };
1316

0 commit comments

Comments
 (0)