Skip to content

Commit a402024

Browse files
Merge pull request #5894 from qburst/enhancement/docs-site-ts
Fix loading indicator flicker when switching TypeScript/JavaScript tabs in docs-site
2 parents 48093c6 + 52dfc5e commit a402024

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

docs-site/src/components/Example/index.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,36 @@ export default class CodeExampleComponent extends React.Component<
6262
registerLocale("en-GB", enGB);
6363
}
6464

65-
transpileTsCode = async () => {
66-
const tsCode = this.state.tsxCode;
65+
applyStateUpdates = (stateUpdates: Partial<TState>) => {
66+
this.setState((state) => ({
67+
...state,
68+
...stateUpdates,
69+
}));
70+
};
6771

68-
let stateUpdates = {
72+
transpileTsCode = async () => {
73+
this.applyStateUpdates({
6974
jsxCode: "",
7075
isTranspiling: true,
71-
};
76+
});
7277

7378
try {
79+
const tsCode = this.state.tsxCode;
7480
const transpiledCode = await transformTsx(tsCode);
7581

7682
this.lastTranspiledTsCodeRef.current = tsCode;
77-
stateUpdates = {
83+
this.applyStateUpdates({
7884
jsxCode: transpiledCode,
7985
isTranspiling: false,
80-
};
86+
});
8187
} catch (err) {
82-
stateUpdates = {
88+
this.applyStateUpdates({
8389
jsxCode: "// Transpilation failed! Error: " + (err as Error).message,
8490
isTranspiling: false,
85-
};
91+
});
8692

8793
toast.show("Transpilation failed!", "error");
8894
}
89-
90-
this.setState((state) => ({
91-
...state,
92-
...stateUpdates,
93-
}));
9495
};
9596

9697
handleCodeChange = debounce((code: string) => {

0 commit comments

Comments
 (0)