Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Named exports with redux?

i have got used to using named exports as it makes life easier for refactoring. I have just started to implement redux but it seems i can't do a named export because the connect needs to map the component.

so for example

class Something extends Component { ... }

export default connect(mapStateToProps)(Something);

Would it be possible to use a named export like "Something", i can't place the export on the class as although react continues to work - the connect is not getting exported so there is no redux state

Any ideas ?

Thanks in advance

like image 606
Mark Smith Avatar asked Jan 30 '19 20:01

Mark Smith


2 Answers

Just assign it to a const and export that like so:

class Something extends Component { ... }

export const ConnectedSomething = connect(mapStateToProps)(Something);

Then you can import it like so:

import { ConnectedSomething } from './....'
like image 73
SakoBu Avatar answered Oct 21 '22 18:10

SakoBu


If I'm understanding correctly, then you could export your "redux connected" component via named export as follows:

/*
Declare component class, with class name differing from named export
*/
class SomethingComponent extends Component { ... };

/*
Export redux connected HOC to external modules, via named export "Something"
*/
export const Something = connect(mapStateToProps)(SomethingComponent);
like image 42
Dacre Denny Avatar answered Oct 21 '22 16:10

Dacre Denny