Skip to content

Commit

Permalink
DataManager: add notes on useMemo workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunanoordin committed Sep 1, 2023
1 parent 02e70df commit 987f1e0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/pages/lab-pages-editor/DataManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function DataManager({
status: 'ready'
});

const [randomFlagToPromptMemoUpdate, setRandomFlagToPromptMemoUpdate] = useState(0);

// Fetch workflow when the component loads for the first time.
// See notes about 'key' prop, to ensure states are reset:
// https://react.dev/learn/you-might-not-need-an-effect#resetting-all-state-when-a-prop-changes
Expand Down Expand Up @@ -82,13 +84,23 @@ function DataManager({
workflow: apiData.workflow,
status: 'ready'
});

// Hmmm... this seems to be the only thing that's updating the context properly.
// Without it, it seems that setApiData() isn't changing the value
// (object reference) of`apiData.workflow`, which means the useMemo
// doesn't realise that oohhh wait I think I get it now.
// TODO: how to indicate that the value of the apiData.workflow object
// has changed when the change is local to the resource itself?
// Does the workflow object have an internal version tracker?
// @shaunanoordin 20230902
setRandomFlagToPromptMemoUpdate(Math.floor(Math.random() * 10000));
}

return {
workflow: apiData.workflow,
update
};
}, [apiData.workflow]); // Note to self: change this to workflowId?
}, [apiData.workflow, randomFlagToPromptMemoUpdate]);

if (!workflowId) return (<div>ERROR: no Workflow ID specified</div>);
// if (!workflow) return null
Expand Down

0 comments on commit 987f1e0

Please sign in to comment.