Skip to content

Commit 7cd4927

Browse files
committed
Refact Component Map to display componentData state, context & props
1 parent 66b4656 commit 7cd4927

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/app/components/StateRoute/ComponentMap/ComponentMap.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ export default function ComponentMap({
126126
const contextFormat = [];
127127
for (const key in data) {
128128
// Suggestion: update the front end to display as a list if we have object
129-
contextFormat.push(
130-
<p className={`${type}-item`}>{`${key}: ${JSON.stringify(data[key])}`}</p>,
131-
);
129+
let inputData = data[key];
130+
if (inputData !== null && typeof inputData === 'object') {
131+
inputData = JSON.stringify(inputData);
132+
}
133+
contextFormat.push(<p className={`${type}-item`}>{`${key}: ${inputData}`}</p>);
132134
}
133135
return contextFormat;
134136
};

src/backend/linkFiber.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ function createTree(
425425
componentData.props = convertDataToString(memoizedProps);
426426
}
427427

428-
// ----------------APPEND STATE DATA FROM REACT DEV TOOL----------------------
428+
// ------------APPEND STATE & CONTEXT DATA FROM REACT DEV TOOL----------------
429429
if (stateNode?.state) {
430430
Object.assign(componentData.state, stateNode.state);
431431
}
@@ -447,7 +447,7 @@ function createTree(
447447
}
448448
// if user uses useContext hook, context data will be stored in memoizedProps.value of the Context.Provider component => grab context object stored in memoizedprops
449449
// Different from other provider, such as Routes, BrowswerRouter, ReactRedux, ..., Context.Provider does not have a displayName
450-
// TODO: need to render this context provider when user use usContext hook.
450+
// TODO: need to render this context provider when user use useContext hook.
451451
if (tag === ContextProvider && !elementType._context.displayName) {
452452
let stateData = memoizedProps.value;
453453
if (stateData === null || typeof stateData !== 'object') {

0 commit comments

Comments
 (0)