2 回答
TA贡献1796条经验 获得超4个赞
我通过将代码从装饰器移动到故事本身中解决了我的问题。显然,从长远来看,这并不理想。
export default {
title: 'MyLovelyComponent',
Component: MyLovelyComponent
}
const UsingReduxComponent = () => {
const dispatch = useDispatch();
useEffect(() => {
dispatch(updateMyData(myData)); // actionCreator for updating state
dispatch(updateLovelyData(lovelyData));
}, []);
return (<MyLovelyComponent />);
}
export const UsingRedux = () => (
<ProviderWrapper>
<UsingReduxComponent />
</ProviderWrapper>
)
TA贡献1875条经验 获得超5个赞
您还必须在提供程序和包装器中传递存储。
import { Provider } from 'react-redux';
import { configureStore } from '../redux/configureStore';
const store = configureStore();
const ProviderWrapper = ({ children, store }) => (
<Provider store={store}>
{children}
</Provider>
);
export const withProvider = (story) => (
<ProviderWrapper store={store}>
{story()}
</ProviderWrapper>
)
// in config.js file
import { withProvider } from './Provider.js';
addDecorator(withProvider);
添加回答
举报