mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
React: Fix hooks support in stories
This commit is contained in:
parent
6c5df85010
commit
24c5fa446a
@ -15,14 +15,14 @@ function render(node: React.ReactElement, el: Element) {
|
||||
}
|
||||
|
||||
export default function renderMain({
|
||||
storyFn,
|
||||
storyFn: StoryFn,
|
||||
selectedKind,
|
||||
selectedStory,
|
||||
showMain,
|
||||
showError,
|
||||
forceRender,
|
||||
}: RenderMainArgs) {
|
||||
const element = storyFn();
|
||||
const element = <StoryFn />;
|
||||
|
||||
if (!element) {
|
||||
showError({
|
||||
|
@ -23,12 +23,11 @@ withSomeEmoji.story = {
|
||||
name: 'with some emoji',
|
||||
};
|
||||
|
||||
export const withCounter = () =>
|
||||
React.createElement(() => {
|
||||
const [counter, setCounter] = useState(0);
|
||||
const label = `Testing: ${counter}`;
|
||||
return <Button onClick={() => setCounter(counter + 1)}>{label}</Button>;
|
||||
});
|
||||
export const withCounter = () => {
|
||||
const [counter, setCounter] = useState(0);
|
||||
const label = `Testing: ${counter}`;
|
||||
return <Button onClick={() => setCounter(counter + 1)}>{label}</Button>;
|
||||
};
|
||||
|
||||
withCounter.story = {
|
||||
name: 'with counter',
|
||||
|
@ -27,10 +27,10 @@ import { Meta, Story, Preview } from '@storybook/addon-docs/blocks';
|
||||
|
||||
<Preview>
|
||||
<Story name="with counter">
|
||||
{React.createElement(() => {
|
||||
{() => {
|
||||
const [counter, setCounter] = useState(0);
|
||||
const label = `Testing: ${counter}`;
|
||||
return <Button onClick={() => setCounter(counter + 1)}>{label}</Button>;
|
||||
})}
|
||||
}}
|
||||
</Story>
|
||||
</Preview>
|
||||
|
Loading…
x
Reference in New Issue
Block a user