第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

故事書添加裝飾者不提供 redux 商店

故事書添加裝飾者不提供 redux 商店

縹緲止盈 2022-09-29 16:44:00
我正在使用故事書和反應(yīng)還原。我在 中有一個全局裝飾器,它像這樣添加商店:preview.jsimport { addDecorator } from '@storybook/react';import ProviderWrapper from '../src/components/Provider'; //Provides the storeaddDecorator(storyFn => <ProviderWrapper>{storyFn()}</ProviderWrapper>提供程序包裝器只是(或多或少):import { Provider } from 'react-redux';import { configureStore } from '../redux/configureStore';const store = configureStore();export const ProviderWrapper = ({ children }) =>    (<Provider store={store}>{children}</Provider>)配置存儲目前非常簡單:const configureStore = () => createStore(reducers);我遇到的問題是,當我嘗試在我的一個組件中使用 react-redux 鉤子并進行設(shè)置時,我會收到以下錯誤消息:could not find react-redux context value; please ensure the component is wrapped in a <Provider>“我的組件”按如下方式使用存儲:const MyLovelyComponent = () => {   const { myData, lovelyData } = useSelector(selectMyLovelyData);   return (      <Paper>        <MyComponent data={myData} />        <LovelyComponent data={lovelyData} />      </Paper>   );};當我在故事中使用它時,我會以這種方式設(shè)置它:export default {    title: 'MyLovelyComponent',    Component: MyLovelyComponent}export const UsingRedux = () => {    const dispatch = useDispatch();    useEffect(() => {      dispatch(updateMyData(myData)); // actionCreator for updating state      dispatch(updateLovelyData(lovelyData));    }, []);    return (<MyLovelyComponent />);}感覺一切都應(yīng)該設(shè)置好工作,所以我無法弄清楚為什么我會得到這個錯誤。如果它有幫助,這里是我的依賴樹fpr反應(yīng)/重做等。根據(jù)這個github問題,這可能與此相關(guān):transformation-comparison@1.0.0 /home/centos/transformation-comparison┠─┰ @storybook/addon-actions@5.3.18│ ┠─┰ @storybook/api@5.3.18│ │ └── react@16.13.1  deduped│ ┠─┰ @storybook/components@5.3.18│ │ └── react@16.13.1  deduped│ └── react@16.13.1  deduped┠─┰ @storybook/react@5.3.18│ └─┰ @storybook/core@5.3.18│   └─┰ @storybook/ui@5.3.18│     └── react@16.13.1  deduped┠── react@16.13.1 ┠── react-redux@7.2.0 └── redux@4.0.5同樣,不確定它是否相關(guān),但有機會它有助于我將其包括在內(nèi)。
查看完整描述

2 回答

?
慕的地8271018

TA貢獻1796條經(jīng)驗 獲得超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>

)


查看完整回答
反對 回復(fù) 2022-09-29
?
慕田峪4524236

TA貢獻1875條經(jīng)驗 獲得超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);


查看完整回答
反對 回復(fù) 2022-09-29
  • 2 回答
  • 0 關(guān)注
  • 120 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號