File tree Expand file tree Collapse file tree 1 file changed +14
-13
lines changed
docs-site/src/components/Example Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Original file line number Diff line number Diff 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 ) => {
You can’t perform that action at this time.
0 commit comments