question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow connect in more than one component connect(props, dispatchs)([Comp1, Comp2])

See original GitHub issue

Hi RR team.

I’m thinking about create the possibility to connect the redux store in more than one component.

Today, we have the following way to connect into one component:

const myContainer = connect(props, dispatchs)(ComponentIWantToConnect) And I’m willing to do this to share the same store:

const myContainer = connect(props, dispatchs)([ComponentIWantToConnect, AnotherComponent])

What do you think about it?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

48reactions
markeriksoncommented, Mar 9, 2017

Okay. So, because connect returns a function, you can do this:

const mySpecialContainerCreator = connect(mapState);

export const FirstConnectedComponent = mySpecialContainerCreator(Component1);
export const SecondConnectedComponent = mySpecialContainerCreator(Component2);

You can re-use the function that is created by connect, rather than only calling it immediately.

Or, I guess you could even do:

const components = [Component1, Component2, Component3];
const connectedComponents = components.map(mySpecialContainerCreator);
1reaction
jimbollacommented, Mar 9, 2017

I don’t understand what you’re trying to accomplish.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connect
The connect() function connects a React component to a Redux store. It provides its connected component with the pieces of the data it...
Read more >
Can I pass multiple components within connect redux
You can only pass one Component to connect. So, instead, you'd have to do two connects:
Read more >
React Redux connect(): When and how to use it
Cover when and how to use the React Redux connect() API to create container components that are connected to the Redux state.
Read more >
How to connect redux to a none default component-Reactjs
You can connect multiple components within the same file, with or without ... export default connect(mapStateToProps, mapDispatchToProps)(WrapperComponent);.
Read more >
React Redux
Any component in your application can be wrapped with connect and "connected" to the store. Connecting more components is usually better for performance....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found