Skip to content

Commit ecad08c

Browse files
committed
Reactor button & Router to work with uptodate react
1 parent 5fd9d1a commit ecad08c

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
lines changed

demo-app-next/src/components/Buttons.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import Increment from "./Increment";
1+
import Increment from './Increment';
22

33
export default function Buttons() {
44
const buttons = [];
55
for (let i = 0; i < 4; i++) {
6-
buttons.push(<Increment />);
6+
buttons.push(<Increment key={i} />);
77
}
88

99
return (
10-
<div className="buttons">
10+
<div className='buttons'>
1111
<h1>Stateful Buttons</h1>
1212
<h4>
13-
These buttons are functional components that each manage their own state
14-
with the useState hook.
13+
These buttons are functional components that each manage their own state with the useState
14+
hook.
1515
</h4>
1616
{buttons}
1717
</div>

demo-app/src/client/Components/Buttons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Increment from './Increment';
44
function Buttons() {
55
const buttons = [];
66
for (let i = 0; i < 4; i++) {
7-
buttons.push(<Increment />);
7+
buttons.push(<Increment key={i} />);
88
}
99

1010
return (

demo-app/src/client/Router.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
3+
import { createRoot } from 'react-dom/client';
34
import { BrowserRouter, Routes, Route } from 'react-router-dom';
45
import Nav from './Components/Nav';
56
import Board from './Components/Board';
67
import Home from './Components/Home';
78
import Buttons from './Components/Buttons';
89
import Test from './Components/Test';
910

10-
const root = document.getElementById('root');
11+
const domNode = document.getElementById('root');
12+
const root = createRoot(domNode);
1113

12-
ReactDOM.render(
14+
root.render(
1315
<BrowserRouter>
1416
<Nav />
1517
<Routes>
@@ -19,5 +21,4 @@ ReactDOM.render(
1921
<Route path='/test' element={<Test />} />
2022
</Routes>
2123
</BrowserRouter>,
22-
root,
2324
);

src/backend/linkFiber.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,25 +188,30 @@ function convertDataToString(
188188
reactimeData: ReactimeData = {},
189189
): ReactimeData {
190190
for (const key in reactDevData) {
191-
// Skip keys that are in exclude set OR if there is no value at key
192-
// Falsy values such as 0, false, null are still valid value
193-
if (exclude.has(key) || reactDevData[key] === undefined) {
194-
continue;
195-
}
196-
// If value at key is a function, assign key with value 'function' to reactimeData object
197-
else if (typeof reactDevData[key] === 'function') {
198-
reactimeData[key] = 'function';
199-
}
200-
// If value at key is an object/array and not null => JSON stringify the value
201-
else if (typeof reactDevData[key] === 'object' && reactDevData[key] !== null) {
202-
reactimeData[key] = JSON.stringify(reactDevData[key]);
203-
}
204-
// Else assign the primitive value
205-
else {
206-
reactimeData[key] = reactDevData[key];
191+
try {
192+
// Skip keys that are in exclude set OR if there is no value at key
193+
// Falsy values such as 0, false, null are still valid value
194+
if (exclude.has(key) || reactDevData[key] === undefined) {
195+
continue;
196+
}
197+
// If value at key is a function, assign key with value 'function' to reactimeData object
198+
else if (typeof reactDevData[key] === 'function') {
199+
reactimeData[key] = 'function';
200+
}
201+
// If value at key is an object/array and not null => JSON stringify the value
202+
else if (typeof reactDevData[key] === 'object' && reactDevData[key] !== null) {
203+
reactimeData[key] = JSON.stringify(reactDevData[key]);
204+
}
205+
// Else assign the primitive value
206+
else {
207+
reactimeData[key] = reactDevData[key];
208+
}
209+
} catch (err) {
210+
console.log('linkFiber', { reactDevData, key });
211+
throw Error(`Error caught at converDataToString: ${err}`);
207212
}
213+
return reactimeData;
208214
}
209-
return reactimeData;
210215
}
211216
// ------------------------FILTER STATE & CONTEXT DATA--------------------------
212217
/**
@@ -368,7 +373,13 @@ export function createTree(
368373

369374
// ----------------APPEND PROP DATA FROM REACT DEV TOOL-----------------------
370375
// check to see if the parent component has any state/props
371-
if (memoizedProps) {
376+
if (
377+
(tag === FunctionComponent ||
378+
tag === ClassComponent ||
379+
tag === IndeterminateComponent ||
380+
tag === ContextProvider) &&
381+
memoizedProps
382+
) {
372383
Object.assign(componentData.props, convertDataToString(memoizedProps));
373384
}
374385

@@ -448,6 +459,7 @@ export function createTree(
448459
const hooksNames = getHooksNames(elementType.toString());
449460
console.log({ hooksNames });
450461
newState.hooksState = [];
462+
componentData.state = {};
451463
hooksStates.forEach((state, i) => {
452464
hooksIndex = componentActionsRecord.saveNew(state.state, state.component);
453465
componentData.hooksIndex = hooksIndex;

0 commit comments

Comments
 (0)