Skip to content

Commit 2de61da

Browse files
committed
[storybook] Adding story to check mount/unmount
1 parent 2781f1e commit 2de61da

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
3+
import { Lifecycle } from './Lifecycle';
4+
import source from './Lifecycle?raw';
5+
6+
const meta: Meta<typeof Lifecycle> = {
7+
component: Lifecycle,
8+
id: 'lifecycle',
9+
title: 'Examples',
10+
};
11+
12+
export default meta;
13+
type Story = StoryObj<typeof Lifecycle>;
14+
15+
export const Default: Story = {
16+
name: 'Testing lifecycle',
17+
args: {},
18+
parameters: {
19+
storySource: {
20+
source,
21+
},
22+
},
23+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { SigmaContainer } from '@react-sigma/core';
2+
import '@react-sigma/core/lib/style.css';
3+
import type Graph from 'graphology';
4+
import { CSSProperties, FC, useEffect, useState } from 'react';
5+
6+
import { useRandom } from './common/useRandom';
7+
8+
export const Lifecycle: FC<{ style?: CSSProperties }> = ({ style }) => {
9+
const { randomGraph } = useRandom();
10+
const [graph, setGraph] = useState<null | Graph>(randomGraph());
11+
12+
useEffect(() => {
13+
const intervalId = setInterval(() => {
14+
setGraph(null);
15+
setTimeout(() => setGraph(randomGraph), 500);
16+
}, 1000);
17+
18+
return () => {
19+
clearInterval(intervalId);
20+
};
21+
}, [randomGraph]);
22+
23+
return (
24+
<>{graph ? <SigmaContainer style={style} graph={graph} settings={{ allowInvalidContainer: true }} /> : null}</>
25+
);
26+
};

0 commit comments

Comments
 (0)