diff --git a/docs-site/src/components/Example/index.tsx b/docs-site/src/components/Example/index.tsx index 18769279a..06a5e9715 100644 --- a/docs-site/src/components/Example/index.tsx +++ b/docs-site/src/components/Example/index.tsx @@ -62,35 +62,36 @@ export default class CodeExampleComponent extends React.Component< registerLocale("en-GB", enGB); } - transpileTsCode = async () => { - const tsCode = this.state.tsxCode; + applyStateUpdates = (stateUpdates: Partial) => { + this.setState((state) => ({ + ...state, + ...stateUpdates, + })); + }; - let stateUpdates = { + transpileTsCode = async () => { + this.applyStateUpdates({ jsxCode: "", isTranspiling: true, - }; + }); try { + const tsCode = this.state.tsxCode; const transpiledCode = await transformTsx(tsCode); this.lastTranspiledTsCodeRef.current = tsCode; - stateUpdates = { + this.applyStateUpdates({ jsxCode: transpiledCode, isTranspiling: false, - }; + }); } catch (err) { - stateUpdates = { + this.applyStateUpdates({ jsxCode: "// Transpilation failed! Error: " + (err as Error).message, isTranspiling: false, - }; + }); toast.show("Transpilation failed!", "error"); } - - this.setState((state) => ({ - ...state, - ...stateUpdates, - })); }; handleCodeChange = debounce((code: string) => {