Storybook with RHF #7444
-
Hello, I trying to make React-Hook-Form work with Storybook. I was followed the Smart Form Component approach (https://react-hook-form.com/advanced-usage#SmartFormComponent) Currently, my situation looks like that:
Source Code:
Would there be someone nice enough to show me how to handle it? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
maybe worth creating an issue with reproducible codesandbox at the storybook repo. |
Beta Was this translation helpful? Give feedback.
-
Approach 1:
BaseComponent (call this in storybook) -> parent (WrapperComponent) -> parent (Component where you wish to use baseComponent) Approach 2: If you wish to use register with storybook. On code level:
Storybook
|
Beta Was this translation helpful? Give feedback.
-
We have crashed into this bug too. |
Beta Was this translation helpful? Give feedback.
-
My use case was slightly simpler, but I ended up using a decorator: const meta = {
title: 'Title',
component: Component,
decorators: [
(Story) => (
<FormProvider {...useForm()}>
<Story />
</FormProvider>
)
],
args: {
name: 'name'
},
} satisfies Meta<typeof Component> |
Beta Was this translation helpful? Give feedback.
-
I just wanted to share what worked for me after trying lots of things:
|
Beta Was this translation helpful? Give feedback.
Approach 1:
BaseComponent (call this in storybook) -> parent (WrapperComponent) -> parent (Component where you wish to use baseComponent)
Approach 2: If you wish to use register with storybook.
On code level:
BaseComponent