Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect redux to a none default component

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.

like image 595
Mohsen Avatar asked Feb 03 '23 19:02

Mohsen


1 Answers

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
like image 69
Jap Mul Avatar answered Feb 12 '23 03:02

Jap Mul