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.

Render props version of connect

See original GitHub issue

We’ve been trying to migrate a lot of our containers from HOCs over to components that use render props

For the sake of consistency we’re doing the same for connect

import PropTypes from "prop-types"
import { connect } from "react-redux"

const ReduxDataHandler = ({ render, ...propsToPass }) => {
    return render(propsToPass)
}

ReduxDataHandler.propTypes = {
    render: PropTypes.func.isRequired
}

const withReduxData = (mapStateToProps, mapDispatchToProps) => {
    return connect(mapStateToProps, mapDispatchToProps)(ReduxDataHandler)
}

export default withReduxData

What would be awesome is if it would be possible to add a built in version of connect that does something similar but doesn’t require adding this unnecessary wrapping. Would something like that be feasible?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:17
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

26reactions
estaubcommented, Oct 28, 2017

+1 . I expect you’ll get a lot more over time.
FWIW, I use Typescript, and it really plays poorly with HOC, IMHO.

7reactions
corlaezcommented, Jan 13, 2018

My 2 cents on this. This can be 100% backwards compatible, just adding a diferent way to connect, nobody breaks and we are all happy. Why relying in custom implementation or yet-another-js-library just to connect with render props?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Render Props - Share code between components
The term “render prop” refers to a technique for sharing code between React components using a prop whose value is a function. In...
Read more >
Render Props - React
A component with a render prop takes a function that returns a React element and calls it instead of implementing its own render...
Read more >
You Don't Need React-Redux. `ReduxConnection`, the render ...
There's a way to use render props with Redux instead of React-Redux's higher-order component: connect . This can fundamentally change how you think...
Read more >
Understanding React Render Props by Example
Render props means that you pass a render function defined by a separate component's props to indicate what should be returned by the...
Read more >
Render Props Pattern
A render prop is a prop on a component, which value is a function that returns a JSX element. The component itself does...
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