Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Commit

Permalink
Merge 7a0fb07 into 4891eb5
Browse files Browse the repository at this point in the history
  • Loading branch information
idarbuashvili committed Dec 25, 2018
2 parents 4891eb5 + 7a0fb07 commit dedfb61
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions connectContextRecursive.js
@@ -0,0 +1,20 @@
import React from 'react'

function recursiveConsume(Consumers, Component, props = {}) {
if (!Array.isArray(Consumers)) {
return <Component />
}

const Consumer = Consumers.shift()

return (
<Consumer>
{ context => (
Consumers.length === 0 ? <Component {...Object.assign({}, context, props)} />
: recursiveConsume(Consumers, Component, Object.assign({}, context, props))
)}
</Consumer>
)
}

export default (...Consumers) => Component => props => recursiveConsume(Array.from(Consumers), Component, props)

0 comments on commit dedfb61

Please sign in to comment.