React: Fix hooks support in stories

This commit is contained in:
Michael Shilman 2019-07-26 14:09:04 +08:00
parent 6c5df85010
commit 24c5fa446a
3 changed files with 9 additions and 10 deletions

View File

@ -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({

View File

@ -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',

View File

@ -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>