Skip to content

Commit

Permalink
fix(DataConsumer): port RenderHandler data context fix to DataConsumer
Browse files Browse the repository at this point in the history
affects: @tao.js/react

DataConsumer is still experimental but the failing from earlier may be fixed by this fix from
RenderHandler's handling of data context args
  • Loading branch information
eudaimos committed Feb 6, 2022
1 parent c5556ed commit 2af1a4f
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/react-tao/src/DataConsumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,32 @@ function recursiveContextGenerator(
getContext,
children,
ctxIdx = 0,
ctxDataArgs = []
ctxDataArgs = null
) {
if (ctxDataArgs == null) {
ctxDataArgs = new Array(ctxList.length);
}
const ctxName = ctxList[ctxIdx];
const context = getContext(ctxName);
if (!context) {
console.warn(
`DataConsumer::Unable to find context for '${ctxName}'. Please check that you have it spelled correctly.`
);
console.info(`DataConsumer::setting context ${ctxName} data arg to null`);
ctxDataArgs[ctxIdx] = null;
return recursiveContextGenerator(
ctxList,
getContext,
children,
ctxIdx + 1,
ctxDataArgs
);
}
if (ctxList.length > ctxIdx + 1) {
return (
<context.Consumer name={`${ctxName}.Consumer`}>
{ctxData => {
ctxDataArgs.push(ctxData);
ctxDataArgs[ctxIdx] = ctxData;
return recursiveContextGenerator(
ctxList,
getContext,
Expand All @@ -31,7 +48,7 @@ function recursiveContextGenerator(
return (
<context.Consumer name={`${ctxName}.Consumer`}>
{ctxData => {
ctxDataArgs.push(ctxData);
ctxDataArgs[ctxIdx] = ctxData;
return children(...ctxDataArgs);
}}
</context.Consumer>
Expand Down

0 comments on commit 2af1a4f

Please sign in to comment.