reactjs - llamar a los Hooks de React en un decorador global para Storybook
Quiero llamar a un hook personalizado de React para todas las historias, sin embargo, no estoy seguro de dónde declararlo. Los hooks personalizados que quiero llamar deben estar en el proveedor de contexto.
¿Hay alguna forma de declarar un proveedor de contexto y hooks personalizados para todas las historias?
import React from 'react';
import { useCustomHooks } from './custom';
import { ThemeProvider } from 'styled-components';
export const decorators = [
(Story) => (
useCustomHooks() // I wanna call custom hooks here but not working because not in provider
<ThemeProvider theme="default">
<Story />
</ThemeProvider>
),
];
Respuesta #1
Sí, en .storybook/preview.js:
import { addDecorator } from '@storybook/react';
addDecorator((Story) =>
<MotionLazyContainer>
<ThemeProvider>
<Story />
</ThemeProvider>
</MotionLazyContainer>
);
