Skip to content

Commit

Permalink
fix(react): move <StackProvider /> up so that useStack() can be u…
Browse files Browse the repository at this point in the history
…sed in `Plugin.wrapStack` (daangn#529)
  • Loading branch information
tonyfromundefined authored Oct 23, 2024
1 parent d7855c3 commit a4a7366
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-donkeys-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stackflow/react": patch
---

move `<StackProvider />` up so that `useStack()` can be used in `Plugin.wrapStack`
5 changes: 2 additions & 3 deletions integrations/react/src/__internal__/MainRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useEffect } from "react";

import type { ActivityComponentType } from "./ActivityComponentType";
import PluginRenderer from "./PluginRenderer";
import { useCoreState } from "./core";
import { usePlugins } from "./plugins";
import { StackProvider } from "./stack";
import type { WithRequired } from "./utils";

interface MainRendererProps {
Expand Down Expand Up @@ -61,7 +60,7 @@ const MainRenderer: React.FC<MainRendererProps> = ({
}) ?? output;
});

return output;
return <StackProvider value={coreState}>{output}</StackProvider>;
};

MainRenderer.displayName = "MainRenderer";
Expand Down
21 changes: 9 additions & 12 deletions integrations/react/src/__internal__/PluginRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { StackflowReactPlugin } from "./StackflowReactPlugin";
import { ActivityProvider } from "./activity";
import { useCoreState } from "./core";
import { usePlugins } from "./plugins";
import { StackProvider } from "./stack";
import type { WithRequired } from "./utils";

interface PluginRendererProps {
Expand Down Expand Up @@ -53,17 +52,15 @@ const PluginRenderer: React.FC<PluginRendererProps> = ({
});

return (
<StackProvider value={stack}>
<ActivityProvider
key={activity.id}
value={{
...activity,
...overrideActivity,
}}
>
{output}
</ActivityProvider>
</StackProvider>
<ActivityProvider
key={activity.id}
value={{
...activity,
...overrideActivity,
}}
>
{output}
</ActivityProvider>
);
},
})),
Expand Down

0 comments on commit a4a7366

Please sign in to comment.