Learn how to quickly get started with Elements in a React project.
We've created a Create React App template, which allows you to create a brand new Elements website in React without any additional setup.
npx create-react-app my-dir --template @stoplight/elementsThen run cd my-dir and yarn start and you will see a basic Elements website in the browser.
To install Elements Dev Portal in an existing React app, follow these instructions.
- Install the @stoplight/elements package with NPM/Yarn.
yarn add @stoplight/elements- In
App.jsimport the API component and CSS file from the Elements library.
import { API } from '@stoplight/elements';
import '@stoplight/elements/styles.min.css';- Add the App component to the output of the app.
<API
apiDescriptionUrl="https://raw.githubusercontent.com/stoplightio/Public-APIs/master/reference/zoom/openapi.yaml"
/>- Now your
App.jsfile should look something like this:
import React from 'react';
import { API } from '@stoplight/elements';
import '@stoplight/elements/styles.min.css';
function App() {
return (
<div className="App">
<API
apiDescriptionUrl="https://raw.githubusercontent.com/stoplightio/Public-APIs/master/reference/zoom/openapi.yaml"
/>
</div>
);
}
export default App;Now start the development server.
yarn startAnd you should see the API reference documentation for the Zoom API!
apiDescriptionUrl- OpenAPI document URL, supportinghttp://,https://, and documents containing$refto other http(s) documents.apiDescriptionDocument- OpenAPI document, provided as YAML string, JSON string or JavaScript object.basePath- Helps when usingrouter: 'history'but docs are in a subdirectory likehttps://example.com/docs/api.hideTryIt- Passtrueto hide the "Try It" panel (the interactive API console).layout- There are two layouts for Elements:sidebar- (default) Three-column design.stacked- Everything in a single column, making integrations with existing websites that have their own sidebar or other columns already.
logo- URL to an image that will show as a small square logo next to the title, above the table of contents.router- Determines how navigation should work:history- (default) uses the HTML5 history API to keep the UI in sync with the URL.hash- uses the hash portion of the URL (i.e. window.location.hash) to keep the UI in sync with the URL.memory- keeps the history of your "URL" in memory (does not read or write to the address bar).
<API
apiDescriptionUrl="https://raw.githubusercontent.com/stoplightio/Public-APIs/master/reference/zoom/openapi.yaml"
router="hash"
/>
import { API } from "@stoplight/elements";
const apiDescriptionDocument = {
openapi: '3.1.0',
info: {
title: 'Some Awesome API',
version: '1.0.0'
},
paths: {
/* ... */
}
};
<API
apiDescriptionDocument={apiDescriptionDocument}
router="hash"
/>