docs: update demo template (#35440)

This commit is contained in:
MadCcc 2022-05-09 16:23:07 +08:00 committed by GitHub
parent be982e164a
commit c897728eb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -223,8 +223,10 @@ class Demo extends React.Component {
'const { $1 } = ReactRouterDOM;',
)
.replace(/([A-Za-z]*)\s+as\s+([A-Za-z]*)/, '$1:$2')
.replace(/export default/, 'const Demo =')}\n\n${
react18 ? 'createRoot(mountNode).render(<Demo />)' : 'ReactDOM.render(<Demo />, mountNode)'
.replace(/export default/, 'const ComponentDemo =')}\n\n${
react18
? 'createRoot(mountNode).render(<ComponentDemo />)'
: 'ReactDOM.render(<ComponentDemo />, mountNode)'
};\n`,
css: prefillStyle,
editors: '001',
@ -253,8 +255,10 @@ class Demo extends React.Component {
react18
? `import React from 'react';\nimport { createRoot } from 'react-dom/client';\n`
: ''
}${sourceCode.replace(/export default/, 'const Demo =')}\n\n${
react18 ? 'createRoot(mountNode).render(<Demo />)' : 'ReactDOM.render(<Demo />, mountNode)'
}${sourceCode.replace(/export default/, 'const ComponentDemo =')}\n\n${
react18
? 'createRoot(mountNode).render(<ComponentDemo />)'
: 'ReactDOM.render(<ComponentDemo />, mountNode)'
};\n`,
css: prefillStyle,
json: JSON.stringify(