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.

Export redux exports

See original GitHub issue

I think it is a better developer experience when binding libs export the exports from the “core” lib. For instance, right now it is common to see developers import from redux and react-redux in the same component:

import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';

This is extra typing, which makes it a little less convenient to use Redux. Additionally, it can be difficult to remember what comes from which library. I have it memorized now, but I used to always use trial and error to figure out where to import things from.

It would be less code to write, and easier for developers to learn and use redux, if the above was:

import { connect, bindActionCreators } from 'react-redux';

React Router does this, and it is 👌:

import { Router, Link } from 'react-router-dom';

Router comes from the react-router package, and Link comes from react-router-dom.

In other words, web users do not need to install react-router and react-router-dom. Redux could have a similar developer experience.

Thanks for reading ✌️

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
markeriksoncommented, Apr 4, 2018

We maintain both redux and react-redux, but they are separate packages.

I don’t see a real need for this. Besides, in most cases, you shouldn’t have to import things from both libraries in the same file. If you’re using bindActionCreators when connecting a React component, I’d encourage you to use the “object shorthand” form of mapDispatch instead:

import {addTodo, toggleTodo} from "./todoActions";

export default connect(null, {addTodo, toggleTodo})(TodoList);

That binds them automatically.

The only other Redux export that you might be using here is compose() for combining multiple HOCs together, and that’s a rarer use case.

0reactions
jamespleasecommented, Apr 4, 2018

I’d encourage you to use the “object shorthand” form of mapDispatch instead:

I had no idea you could do that! That’s pretty rad ✌️

I agree with you @markerikson . This isn’t an issue given you can pass an object as that argument to connect.

Thanks for responding!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Named exports with redux? - reactjs - Stack Overflow
I have just started to implement redux but it seems i can't do a named export because the connect needs to map the...
Read more >
Other Exports | Redux Toolkit
Redux Toolkit exports some of its internal utilities, and re-exports additional functions from other dependencies as well.
Read more >
How to Export a Connected Component - Dave Ceddia
It's perfectly valid to export the unconnected component and the connected one. This can be useful for testing – say, when you want...
Read more >
Avoid ES6 default exports - Rajesh Naroth - Medium
I constantly combine exports in index.js from a component or helper folder. // index.jsexport { Title } from "./components/title";
Read more >
Cannot import redux-toolkit from a Node.js ESM module #1960
I have a bit of an unusual setup where I use redux-toolkit also in the ... Instead, Node.js uses the exports property to...
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