diff --git a/integrations/react/src/future/ActivityComponentMapProvider.tsx b/integrations/react/src/future/ActivityComponentMapProvider.tsx index f7deadb8..354b1cb4 100644 --- a/integrations/react/src/future/ActivityComponentMapProvider.tsx +++ b/integrations/react/src/future/ActivityComponentMapProvider.tsx @@ -2,8 +2,11 @@ import { createContext } from "react"; import type { ActivityComponentType } from "../stable"; type Value = { - activityComponentMap: { [key: string]: ActivityComponentType }; - set: (key: string, value: ActivityComponentType) => void; + activityComponentMap: { [activityName: string]: ActivityComponentType }; + setActivityComponentMap: (args: { + activityName: string; + Component: ActivityComponentType; + }) => void; }; export const UNSAFE_ActivityComponentMapContext = createContext( diff --git a/integrations/react/src/future/stackflow.tsx b/integrations/react/src/future/stackflow.tsx index 70552f95..8747e462 100644 --- a/integrations/react/src/future/stackflow.tsx +++ b/integrations/react/src/future/stackflow.tsx @@ -9,7 +9,7 @@ import { makeCoreStore, makeEvent, } from "@stackflow/core"; -import React, { useMemo, useState } from "react"; +import React, { useMemo, useReducer } from "react"; import MainRenderer from "../__internal__/MainRenderer"; import { makeActivityId } from "../__internal__/activity"; import { CoreProvider } from "../__internal__/core"; @@ -155,21 +155,22 @@ export function stackflow< return store; }, []); - const [activityComponentMap, setActivityComponentMap] = useState( - () => input.components, + const [activityComponentMap, setActivityComponentMap] = useReducer< + React.Reducer< + { [activityName: string]: ActivityComponentType }, + { activityName: string; Component: ActivityComponentType } + > + >( + (map, { activityName, Component }) => ({ + ...map, + [activityName]: Component, + }), + input.components, ); return ( ({ - ...map, - [key]: value, - })); - }, - }} + value={{ activityComponentMap, setActivityComponentMap }} >