I have a file with multi component that I want to export and connect all to redux, how can I do this?
Connect wrapper need to export default, but I have multi component.
You don't have to export default to use connect. You can connect multiple components within the same file, with or without exporting them. Although I would recommend only placing 1 component per file
import React from 'react'
import { connect } from 'react-redux'
// This also works without the export statement
export const Comp1 = connect(
state => ({
someProp: state,
})
)(({ someProp }) => (
<div>
<h1>Comp 1</h1>
<p></p>
</div>
))
const Comp2 = connect(
state => ({
someProp: state,
})
)(({ someProp }) => (
<div>
<h1>Comp 2</h1>
<p></p>
</div>
))
export default Comp2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With