-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ContextualSaveBar.tsx
38 lines (33 loc) · 1.08 KB
/
ContextualSaveBar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from 'react';
import {ContextualSaveBarProps, useFrame} from '../../utilities/frame';
// The script in the styleguide that generates the Props Explorer data expects
// a component's props to be found in the Props interface. This silly workaround
// ensures that the Props Explorer table is generated correctly, instead of
// crashing if we write `ContextualSaveBar extends React.Component<ContextualSaveBarProps>`
export interface ContextualSaveBarProps extends ContextualSaveBarProps {}
export const ContextualSaveBar = React.memo(function ContextualSaveBar({
message,
saveAction,
discardAction,
alignContentFlush,
}: ContextualSaveBarProps) {
const {setContextualSaveBar, removeContextualSaveBar} = useFrame();
React.useEffect(() => {
setContextualSaveBar({
message,
saveAction,
discardAction,
alignContentFlush,
});
}, [
message,
saveAction,
discardAction,
alignContentFlush,
setContextualSaveBar,
]);
React.useEffect(() => {
return removeContextualSaveBar;
}, [removeContextualSaveBar]);
return null;
});