ReactRedux: How to map to more than one state object and action creator? #1536

Closed
opened 2025-08-09 17:20:31 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @empz on 7/1/2016

Take the example of the FetchData.tsx component which at the end of the file contains the following code that generates the type for the props and connects to the redux store.

// Build the WeatherForecastProps type, which allows the component to be strongly typed
const provider = provide(
    (state: ApplicationState) => state.weatherForecasts, // Select which part of global state maps to this component
    WeatherForecastsState.actionCreators                 // Select which action creators should be exposed to this component
).withExternalProps<{ params: RouteParams }>();          // Also include a 'params' property on WeatherForecastProps
type WeatherForecastProps = typeof provider.allProps;
export default provider.connect(FetchData);

If I wanted to use another part of the state (without losing the weatherForecasts part of course)... how would I map that?
Same question for the actionCreators.

Is there an easy way to "merge" them? Or is having a 1-to-1 mapping between containers and store modules the only option?

*Originally created by @empz on 7/1/2016* Take the example of the `FetchData.tsx` component which at the end of the file contains the following code that generates the type for the props and connects to the redux store. ``` typescript // Build the WeatherForecastProps type, which allows the component to be strongly typed const provider = provide( (state: ApplicationState) => state.weatherForecasts, // Select which part of global state maps to this component WeatherForecastsState.actionCreators // Select which action creators should be exposed to this component ).withExternalProps<{ params: RouteParams }>(); // Also include a 'params' property on WeatherForecastProps type WeatherForecastProps = typeof provider.allProps; export default provider.connect(FetchData); ``` If I wanted to use another part of the state (without losing the `weatherForecasts` part of course)... how would I map that? Same question for the actionCreators. Is there an easy way to "merge" them? Or is having a 1-to-1 mapping between containers and store modules the only option?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#1536
No description provided.