Forge Developer

Beta

Forge Developer

Beta

Rate this page:

Code

A component used to display code snippets.

Usage

1
import ForgeUI, { Code } from '@forge/ui';

Props

NameTypeRequiredDescription
textstringYesThe code to be formatted.
languagestringThe language in which the code is written.

Example

An example app that displays the stringified code block.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const App = () => {
  const exampleCodeBlock = `  // React Component
    class HelloMessage extends React.Component {
      render() {
        return (
          <div>
            Hello {this.props.name}
          </div>
        );
      }
    }
  
    ReactDOM.render(
      <HelloMessage name="Taylor" />,
      mountNode
    );
  `;
  return (
    <Code text={exampleCodeBlock} language="javascript" />
  );
}; 

Preview

Screenshot of what the rendered code component should look like

Rate this page: