MCPcopy Index your code
hub / github.com/blocks/blocks / CodeMode

Function CodeMode

packages/blocks-ui/src/modes/code.js:12–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10import { CodeEditor } from '../code-editor'
11
12const CodeMode = () => {
13 const { code, editCode } = useCode()
14 const [formattedCode, setFormattedCode] = useState('')
15
16 useEffect(() => {
17 const rawCode = transforms.toRawJSX(code)
18 setFormattedCode(
19 prettier.format(rawCode, {
20 parser: 'babel',
21 plugins: [parserJS]
22 })
23 )
24 }, [])
25
26 const onCodeChange = code => {
27 try {
28 editCode(code)
29 } catch (e) {
30 // do nothing as the errors are displayed in the editor
31 }
32 }
33
34 return (
35 <CanvasWrap>
36 <CodeEditor code={formattedCode} onChange={onCodeChange} />
37 </CanvasWrap>
38 )
39}
40
41export default CodeMode

Callers

nothing calls this directly

Calls 1

useCodeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…