github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/.storybook/decorators/withRouterProvider.tsx (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 import React from "react"; 12 import {Provider} from "react-redux"; 13 import {ConnectedRouter, connectRouter} from "connected-react-router"; 14 import {createMemoryHistory} from "history"; 15 import { createStore, combineReducers } from "redux"; 16 import {RenderFunction} from "storybook__react"; 17 18 const history = createMemoryHistory(); 19 const routerReducer = connectRouter(history); 20 21 const store = createStore(combineReducers({ 22 router: routerReducer, 23 })); 24 25 export const withRouterProvider = (storyFn: RenderFunction) => ( 26 <Provider store={store}> 27 <ConnectedRouter history={history}> 28 { storyFn() } 29 </ConnectedRouter> 30 </Provider> 31 );